Monolith, Modular Monolith and Microservices
Weigh the real costs and benefits of monoliths and microservices, and learn how teams split systems along business boundaries when they need to.
Intermediate · about 3 hours · difficulty 3/5
Learn first: API Design: REST, gRPC and GraphQL, Message Queues and Async Processing
"Should this be microservices?" is one of the most common design questions and one of the most over-answered with "yes".
Monolith
One deployable application with one codebase and usually one database. Simple to build, test, deploy and debug; transactions are local; no network calls between modules. Scales well horizontally behind a load balancer. Many large Indian products ran as monoliths far longer than people assume.
Modular monolith
Still one deployable, but with strict module boundaries (separate packages, owned tables, internal APIs between modules). You keep the operational simplicity while preparing clean seams for later extraction. Often the best default.
Microservices
Many small services, each owning its data and deployed independently. Benefits:
- Team autonomy: 20 teams can ship without coordinating one release.
- Independent scaling and technology choice per service.
- Fault isolation, if designed for it.
Costs:
- Network calls everywhere: latency, partial failures, retries.
- Distributed data: no joins or ACID transactions across services; sagas and eventual consistency.
- Operational load: service discovery, tracing, CI/CD per service, versioned contracts, on-call for each.
How to split
Use domain-driven design ideas: find bounded contexts (catalog, cart, orders, payments, delivery) where language and data are cohesive. Each service owns its data; others access it only through APIs or events. Use the strangler fig pattern to extract pieces from a monolith gradually.
Pitfalls
- A distributed monolith: services that must deploy together and share a database.
- Splitting by technical layer (a "DB service") instead of business capability.
- Five services for a three-person startup.
You are ready to move on when you can argue for a modular monolith for an early-stage startup and for microservices at Swiggy's scale, using team size, deploy frequency and data ownership as reasons.
Key concepts
- Monolith strengths
- Modular monolith
- Microservices benefits and costs
- Bounded contexts (DDD)
- Database per service
- Strangler fig migration
- Distributed monolith anti-pattern
Mini project
Take a monolithic e-commerce app (yours or an open-source one), draw its bounded contexts, and write a migration plan that extracts one context (for example notifications) using the strangler fig pattern, including data ownership changes.
Check yourself
Name three signs that a set of microservices is actually a distributed monolith.
Free resources
- Microservices (Martin Fowler)
- MonolithFirst (Martin Fowler)
- Microservice architecture patterns (microservices.io)
- Strangler fig application (Martin Fowler)