Ye Olde Monolith
Take a look at what it takes to make a monolith work (and the many, many ways it can go wrong at the code, developer, and organization levels).
Join the DZone community and get the full member experience.Join For Free
as a professional software engineer, you have probably encountered an architectural stumbling block known as a monolith . a monolith is essentially a single-tier application in enterprise architecture. forget about the traditional breakdown of java ee applications, where they break down an uber-war file into presentation, business-logic, and database tiers. that is just gloss hiding the truth from our eyes. a single war file deployed to an application server is, at best, a monolith.
in my contracting experience, i have witnessed many types of monoliths at various stages of software development lifecycle. unfortunately, i have been around toward the latter end of the software development lifecycle, where the monolith application is already in maintenance mode or has been reiterated several times. it is the nature of contracting that the conditions of bit rot have already been set and are irreversible.
a monolith has the following characteristics:
- the application code is generally unfathomable because the modules are inextricably interlinked, making analysis absurdly complex.
- the time of development cycles gradually increases through each milestone release.
- there is a vast swathe of code and modules. i would say more than 500,000 lines of code and more than 250 modules is de-rigour.
- the ratio of unit test classes to regular code is alarmingly very low, sometimes much less than 5%.
- usually, there are only one or two persons in the organisation who have any clue how the whole monolith hangs together.
- there is a culture of resistance to change. sometimes that culture is political.
- people have passed through the eye of the needle many times over.
how do monoliths come to being? who is responsible? i have my suspicions about the origin. in my experience, they are started when a business generates and builds software from a brownfield environment.
how does a monolith actually start? it starts with a basic requirement, or what appears to be fundamental, and then deviates into the asylum from the start date. the weird thing is that it does not matter if you have average engineers or a crack team of skunk workers, with at least 10 years’ experience and, say, everyone with technical architectural leadership experience in the past. software, unfortunately, is very subjective. we have all opinions on the best framework, the best library, and we are limited by the constraints we have in our knowledge at the time of the monolith’s conception.
why do i call the initial conditions brownfield? because there is rarely a case in a prototype or starter version where we build everything from scratch. a monolith starts with a dependency like java ee, if the code is written in java. it will be different if your monolith is written in php, python, groovy, scala, or ruby.
here is an extract of an old proposal document that i have:
universal trade desk add-on
what is utd and why are we building it?
how is it being implemented?
when will it be delivered and what will be included?
where are we now?
summary and future development / roadmap
“this new application will be a near real-time trading desk add-on to provide consolidated single source of trade data in a format understandable by x-quantlib exposure library (x-qel). the contents of utd will be updated upon trade lifecycle events and will be available via an api. traders will be migrated from legacy-y to utd in progressive steps. utd will be available across the web and also desktop profiles.”
from the above sample description, which was written in 2009, i have changed some terms. you can see exacting business knowledge [jargon] is required. if i went back in time from 2016 and looked at this application, it would likely be a monolith, and i doubt that i would find the original document that described the start of the journey. in fact, i have engaged in a few contracts, and the client can no longer find the original bufd.
a monolith is characterized by the culture that creates it. as soon as code is written, some say you already have technical debt. in effect, writing code, even with unit tests, is like taking an option on the future. if you know that code is just a prototype, then you can afford to cut corners and deliver the fast working example of the application that impresses the stakeholder.
monoliths rarely get thrown away or restarted. there is an early day scenario where the majority of the application should be rebuilt from scratch, but because of business pressures like cost, time-to-market, and finance, nobody ever does this. over time, the monolith keeps growing and stretching further into the distance.
after person years, this mountain of code keeps growing every day, every month and every year. why? because a monolith is nothing except a transformation of a viable business model, in other words, as long the business makes a profit, then it will self-sustain.
monoliths to date are also a victim of software engineering trends. we can look at the technology and the libraries. the biggest java monoliths were probably created long before spring framework, guice, and cdi. java did not have annotations or even generics. even best practices change with time. by 2016, the j2ee design patterns are woefully past their sell-by date. i would add controllers written against apache struts version 1.0 to mix.
at best, the monoliths were never modularized or designed for best practice of components.
conway’s law asserts that organizations are constrained to produce application designs that mirror their communication infrastructures. no matter how adaptive an organization tries to break out beyond the law, the result always is unintended communication breakdowns between management, departments, and silos; which all require resolution.
unsurprisingly, monoliths will exhibit the structure of the people that created and also maintain them.
a monolith is also affected by staff turnover . if a new business team has an original idea of an application at the very beginning, after a few years, the direction of the application will change. old staffers leave the business and original consultants and contractors leave the project as new people arrive. the new staff must learn new concepts, and they are rarely handed over in a fashion that shows maximum knowledge transfer.
because the business relied on selling their software to customers as a bespoke monolith, there were most likely promises to get extensions to the monolith finished by a certain date. i suspect that the extension and final application were underestimated and, like the majority of software projects in the industry, finally arrived considerably over the expected budget.
the problem is that monoliths have within themselves undue complexity in terms of logic. an extension of the application is dependent on several factors:
- comprehensive view of the monolith’s internal working components.
- sufficient translation of new business requirements to technical requirements.
- adapting old components and developing new components.
- dealing with the stress of mixed capable staff.
- unknown impedances in the code, framework, and databases.
these above are the forces acting on an aging monolith. at the very beginning of the sdlc, these forces are still there. however, the complexity of the code and initial requirements are smaller.
time to market
lack of unit tests
depending on the age of the monolith, they demonstrate a shocking minimal degree of unit test coverage. the worst monolith that i ever saw had a ratio of 0.2% test coverage, according to a sonarqube analysis.
the lack of unit tests revealed that time-to-market was a crucial factor in the past. some application monoliths were written before dependency injection had taken a foothold in the industry. there were so many static class factory singletons that it made testing very difficult. while there was one client that i saw had various degree of success with power mockito , even those monoliths that had tests that invariably were not verifying or validating enough outputs against expected inputs.
lack of know-how
with dependency injection and modules in general, the industry has shown over the past decade a lack of genuine know-how. it takes a while to design a modular application system effectively, and most people need experience.
we have searched for shortcuts in building systems. we have struggled over 25 years attempting to build object-oriented applications and systems. it is hardly a surprise that monoliths come into being because there is plenty of evidence of what not to do: anti-patterns .
failure to keep up-to-date
as we add more features and functions to a monolithic application, and in particular, one that we never throw away, we end up layering complexity on more complexity. it is a bit like having an open wound. the sensible thing would be to put a bandage on it because we think it is the quickest way to alleviate the pain and suffering. however, an open wound is not a straightforward cut. it requires antiseptic, cleaning, minor or major surgery, and then proper bandages followed by recovery. software engineers don’t clean bad code or change the code smells. it stays infected and becomes worse.
meanwhile, software development continually finds a brand new way. the java language introduces annotations one year. in the following years, it introduces functional interfaces, lambdas, and streams. yet with a huge mass of monolith with severe complexity and incomprehensibility, it is nearly impossible to use any of those recent features. for one, the management or the stakeholders that fund the monolith and keep the good ship afloat are petrified of the risk of any advancement. for another, politics and the business model mean that they deliberately fail to keep the monolith up to date with technology.
can a monolith be beautiful?
dhh describes his views on the hype regarding microservices oriented architecture (msoa) . he thought that we were blinded and prone to over-engineering new systems like microservices. instead, he pointedly described basecamp as a “majestic monolith” that benefited from a dynamic programming language; and over the past decade, optimizations in operating system functionality and cpu performance. dhh argued against going for distributed computing applications at the outset, especially in a small setup.
i found his views reassuring for the monolithic application. however, i observed that basecamp, and i have never seen the code, has been under his complete control since the beginning. every check-in of code into the version control system was most likely validated. dhh and jason fried are unusual because they are the architects who have stayed with their software. architects often drop out of coding activities and mostly move on to other software systems and join other companies. additionally, there is no way to see the “beauty” of basecamp without examining the application code, infrastructure and, of course, the people culture at 37 signals. so while i think a monolith can be magnificent and even majestic, it is a very tall order to ensure that it remains beautiful as time marches on.
there is a severe downside to monoliths in commercial companies. they are not normally open source and, therefore, they cannot be subject to independent critical reviews, not even of the structural engineering, security, and compliance types. i suspect that the beauty of a monolith is in the eyes of the architectural beholder and can be used as leverage — like a big stick to beat the development staff with it. “this is how it works here, this is what we have and this is how we are going to do it in order to get the delivery out of the door for milestone x.” in other words, beauty does not pay the bills. so in the end, we eventually finish with ugly monoliths, and they persist until a critical juncture, which might be business model failure and disruptive entries from the competition.
a java ee monolith is broken when it exhibits the following characteristics:
- it was not written from the beginning (five years ago) as a modular application where modules are self-contained with high cohesion and reduced coupling.
- original architects have left the building and stage; and the current owners have no clue about deep internals.
- it is a representation of the political infighting status, managerial power, and intrigue.
- the organization is resistant to changing the monolith — worldly consultants and contractors have a tough time getting management to listen.
- there is a distinct lack of unit tests, sometimes with less than 10% coverage, and integration testing is hard because it falls one or two scrum sprints beyond the current one.
- it is extremely hard to get around hard-coded dependencies, such as customer detail, test databases, and limited environments. in other words, testing the simplest code turns into a nightmare.
- the monolith has severe dependencies on legacy libraries from a decade or more years ago: struts 1.x, webwork, tapestry, spring framework 1 or 2, and xml configuration.
- the standard build chain is complicated and takes a very long time.
- even if management suddenly gave the green light to the entire development team today, there would be a huge mountain to climb to adopt java se/jdk 9, and the application code has not evolved much beyond java se 6 (2007).
all of these problems reflect the company’s origin, the culture, and people organization. and there you have it, ye olde monolith.
Published at DZone with permission of Peter Pilgrim, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.