Monolith vs microservices
A monolith is one deployable application. Microservices split the system into small services, each owning one business capability and its own data, talking over the network.
Why it matters
As a product and team grow, one big codebase becomes slow to build, risky to deploy and hard for many teams to work on at once. But splitting it creates network and data problems.
The idea
A monolith is simpler to build, test and deploy at first. Microservices let teams deploy independently and scale parts separately, but add network calls, partial failures, distributed data and running costs. A good path: start with a well-structured (modular) monolith, and split off services when there's a clear reason.
A monolith is a Swiss army knife: one tool, many blades. Microservices are a toolbox of separate tools: each is better and replaceable, but you need a box, labels and more organisation.
Tools in a box don't depend on each other. Services call each other over a network that can be slow or fail, so 50 carelessly built services can be far less reliable than one knife.
How it works
- Find boundaries around business capabilities: users, catalogue, orders, payments.
- Give each service its own database. Other services get its data only through its API or its events.
- Use synchronous calls (REST or gRPC) when an answer is needed now, and events for things that can happen later.
- Put a gateway at the edge, add tracing across services, and give each service its own deployment pipeline.
- Split gradually: carve one service out of the monolith at a time (the 'strangler fig' approach).
Example
An online shop splits into user, catalogue, order, payment and notification services, each with its own database. The order service publishes 'order placed' events that the payment and notification services react to.
Key points
- Each service owns its data; services don't share a database.
- They communicate through APIs (synchronous) or events (asynchronous).
- You'll need: service discovery, an API gateway, distributed tracing, and a deployment pipeline per service.
- Data consistency across services is eventual; use sagas for multi-step workflows.
- Conway's law: a system's structure tends to mirror the teams that build it.
Trade-offs
- Monolith: simple, fast to change early, one deployment; can become tangled and hard for many teams.
- Microservices: independent deployments and scaling; network failures, complexity and data consistency costs.
Common mistakes
- Splitting by technical layer (a 'database service') instead of by business capability.
- Chains of synchronous calls six services deep.
- A small team starting a new product as 30 microservices.
Not true: A new product built by a small team should start as microservices.
In fact: Microservices cost effort from the first day: networks between parts, many deployments, tracing. A small team moves faster with a monolith, and can split it later.
Not true: Splitting into services: by technical layer, such as one 'database service'.
In fact: Then every feature needs changes in several services at once. Split by business capability (orders, payments, shipping), so each team owns one whole piece.
In the interview
I'd start with a modular monolith unless there's a clear need for independent scaling or many separate teams. If we split, each service owns its data, services talk through APIs and events, and we invest in a gateway, tracing and automated deployments from day one.
Part of Unit 4: Distributed systems and security in the free System Design course.