image blog what is a modular monolith
June 18, 2020

What Is a Modular Monolith?

Java Application Development
Enterprise Development

A modular monolith is a software design approach in which a monolith is designed with an emphasis on interchangeable (and potentially reusable) modules.

For many companies unable to make the move to microservices, the modular monolithic approach marks an intermediary ground that claims some of the benefits of microservices – like more manageable dependencies and increased code reusability – without requiring the time-consuming and complicated transition to microservices. But, as we look at later in the article, a modular monolith doesn't seize upon the big benefits of microservices, either.

In this article, we look at some of the benefits of a modular monolith, compare modular monoliths vs. microservices and traditional monolithic applications, then discuss when and when not to use this approach.

Benefits of a Modular Monolith

As mentioned above, adopting the modular approach for monolithic applications can have benefits in a few key areas, including better-organized dependencies, increased code reusability, and increased code observability.

1. Increased Reusability

For large development teams, developing modular components of an application helps to increase reusability. Modular components can be reused and repurposed and can help teams establish a single source of truth. This can lead to faster and more consistent development.

2. Better-Organized Dependencies

Because modular monoliths make individual functions more independent, they, by nature, make dependencies more organized and visible. This makes it easier for developers to easily assess which parts of the application require which dependencies.

3. Increased Observability

Developing with modularity in mind means code is more accessible to developers. For Java developers in particular, interface classes and their requisite javadoc comments helps to enhance accessibility and interoperability for developers who may need to work with the modularized function. 

Modular Monolith vs. Microservices

With the above benefits in mind, how does a modular monolithic approach compare against a true microservices architecture?

The key difference, and one that Kamil Grzybek points to in his article series on this topic, is that monoliths, both modular and non-modular, have one deployment unit while microservices can be deployed independently from one another.

Modular Monolith vs. Microservices Benefits
Modular Monolith BenefitsMicroservices Benefits
Developed code is reusable.Developed code is reusable
Has better-organized dependencies than standard monolith.Has far fewer code dependencies than modular or standard monolith.
Better code observability than standard monolith.Better code observability than modular or standard monolith.
Less complex than microservices application.CI/CD and cloud ready.
 Suitable for granular scaling.
 Multi-technology, Multi-language compatible.
 Suitable for parallel, agile development.

The "single deployment" concept has bigger consequences than deployment speed alone and limits the capacity for disposability – a key benefit of microservices. As an example, imagine a microservices application that receives a petabyte of data it needs to process. It receives the data, spins up as many services needed to handle that data, then disposes of those services once the data has been processed.

A moonolithic application, whether modularized or not, isn’t capable of that same horizontal scaling, and is limited by the speed at which the existing services and underlying hardware can process that data.

Monolith vs. Modular Monolith

For development teams considering using a monolith vs. modular monolith, there are a few key differences between the two approaches.

Monolith vs. Modular Monolith Benefits
Monolith BenefitsModular Monolith Benefits
Low operational complexity.Low operational complexity.
Can be more secure than microservices application.Can be more secure than microservices application.
Easy to manage database consistency.Easy to manage database consistency.
Less complex than microservices application.Less complex than microservices application.
 Developed code is reusable.
 Has better-organized dependencies than standard monolith.
 Better code observability than standard monolith.

For most monolithic Java applications, developers can benefit from using a modular approach – especially at the enterprise level.

When to Use a Modular Monolith

Essentially any time a developer is working on a monolithic application, using principles of modularity can help them to improve the processes for their team. Whether that means making dependencies more manageable within the application, improving developer interoperability on the modular components of that application, or adding modular components to the house repository, embracing modularity can have a positive impact on teams.

For the application itself, embracing modularity can help to organize dependencies, making it easier and less time-consuming to change components within the system.

When Not to Use a Modular Monolith

Of course, just as microservices aren’t a one size fits all solution, neither is modularity. For developers working on small projects with small development teams, developing their code in a modular way may not be worth the added time, or formality.

Final Thoughts

If you’re like many Java developers who are still working on a monolithic application, then employing modularization best practices can help make your application achieve some of the benefits of microservices without the associated cost of refactoring.

However, modular monoliths have significant shortcomings when compared to microservices -- especially in terms of continuous testing, integration, and deployment. 

Additional Resources

Looking for further information on architectural approaches in Java? In the webinar below by Rod Cope, CTO at Perforce, he gives a high-level overview of microservices, miniservices, and monolith architectures, and when it makes sense to use each type.

For additional information on modular monoliths, microservices, and other considerations for application architecture, the resources below offer some good information.

Looking for other ways to speed up development on your monolithic application? Try JRebel. It completely skips rebuilds and redeploys, allowing for faster, more iterative coding. Try it free today on your project by clicking the button below.

Try JRebel Free