Most monoliths start tidy and end tangled. Any class can call any other and any query can join any table, so after a few years every change touches everything. A modular monolith keeps the single deployable application but adds enforced walls inside it.
How it differs from a plain monolith
Both deploy as one unit with one database. The difference is discipline:
- Modules match business areas, such as
accounts,payments,lendingandnotifications. They are not technical layers like "controllers" and "repositories". - Each module owns its tables (or its own schema). Other modules don't query them directly.
- Modules talk through a public interface: an internal API, or in-process events.
- Tooling enforces the boundaries. The build fails if code reaches into another module's internals.
Without the last point, it is just a monolith with tidy folders.
Example: a lending app on Spring Boot
com.example.lending
├── applications/ # public: ApplicationService, LoanApplied event
│ └── internal/ # repositories, scoring rules (hidden)
├── disbursement/ # listens to LoanApproved, calls the bank API
├── repayments/ # schedules EMIs, owns repayment tables
└── notifications/ # listens to events, sends SMS and email
A test in the build checks the structure:
@Test
void modulesRespectBoundaries() {
ApplicationModules.of(LendingApplication.class).verify();
}
Spring Modulith fails this test if repayments imports a class from applications.internal, or if two modules depend on each other in a cycle. When a loan is approved, applications publishes LoanApproved. disbursement and notifications react to it, but applications doesn't know they exist.
Other stacks have equivalents. Rails teams use Packwerk, which Shopify released in September 2020. Java teams also use ArchUnit, and .NET teams use separate projects with internal visibility.
Modular monolith vs microservices
| Modular monolith | Microservices | |
|---|---|---|
| Deploys | One | Many |
| Cross-module consistency | Database transactions | Sagas and eventual consistency |
| Calls between modules | In-process, fast | Network, slower, can fail |
| Independent scaling | No | Yes |
| Operating cost | Low | High |
The modular monolith gives you most of the design benefits, such as clear ownership and separable domains, without the operating cost. It also keeps a door open. When one module needs independent scaling or isolation, its boundary already exists and extraction is far easier. This is the starting point we recommend in monolith vs microservices for startups.
Modular monolith vs distributed monolith
A distributed monolith is the opposite outcome: separate services that share a database or must be released together. It has the network costs of microservices and the coupling of a monolith. Teams often get there by splitting a tangled monolith into services before drawing module boundaries.
Shopify is a well-known case. In 2019 it described choosing to evolve its large Rails codebase into a modular monolith with enforced component boundaries, instead of moving to microservices.
Common mistakes
- Modules sharing tables "just for this one report". Build a read model or a reporting view instead.
- Boundaries written in a wiki but not checked in CI.
- Too many tiny modules early on. Start with five to ten business areas.
We design and restructure application architecture as part of our product engineering work.