Monoliths & Modular Monoliths
A monolith can be a strong architecture when modules have explicit boundaries. “Monolith” describes deployment shape, not necessarily code quality.
Benefits
- one deployment/rollback unit;
- in-process calls and transactions;
- easier local debugging/refactoring;
- lower network/observability burden;
- simpler consistency for many workflows.
Modular structure
app
├─ orders
│ ├─ public API
│ └─ private implementation
├─ billing
└─ identity
Modules own tables/collections where possible and communicate through public module APIs/events rather than importing private repositories.
Dependency rules
Enforce allowed imports through package boundaries, lint/build rules, review, and tests. A folder named modules does not create modularity if everything imports everything.
Scaling
You can scale the whole monolith horizontally before extracting services. If one workload dominates CPU or background jobs, move that execution path first rather than pre-splitting every domain.
Extraction path
- define internal module contract;
- remove cross-boundary direct data access;
- introduce event/outbox/API where needed;
- measure operational reason to extract;
- move one boundary with compatibility plan.
The best microservice migrations often begin by creating a good modular monolith.