Topic 143 / Core
Monolith vs microservices, including when to stay a monolith
Chapter 9.1 · The Decision
What and why
As a system and its team grow, a single deployable unit couples unrelated work — one team's bug fix waits on another's release train, one hot path forces the whole application to scale. Microservices split a system into independently deployable services, each owning its own data and release cycle, communicating over the network. The trade is explicit: every problem Part 8 covers — partial failure, network partitions, eventual consistency — becomes a fact of daily operation, in exchange for independent deployment and scaling. A microservice architecture is a set of small, independently deployable services, each owning its data, composed over the network to deliver one product. Builds on: → 53 (modular monolith architecture).
Diagram
| Dimension | Monolith (incl. modular) | Microservices |
|---|---|---|
| Deployment unit | One | Many, independent |
| Data ownership | One database (modules share it) | One database per service (→ 146) |
| Scaling | Whole app scales together | Each service scales to its own load |
| Failure mode | An in-process bug can crash everything | Isolated failure, but network calls add partial failure (→ 126) |
| Team model | Fits one or a few teams | Suits many teams owning separate services (→ 145) |
| Debugging | Single stack trace | Distributed tracing across services, correlation needed |
| Cost at small scale | Low | High — N deployments, N data stores, network overhead |
How it works
- Start from the modular monolith (→ 53): enforce module boundaries in one deployable, one database with separated schemas.
- Measure the actual pressure: team size outgrowing one release train, modules needing to scale or deploy at different rates, or a module whose technology or data needs diverge sharply.
- If the pressure is real and persistent, extract along a bounded context (→ 56) — not before.
- Expect the extraction to buy independence and pay for it in distributed-system problems: network calls where there were function calls, data consistency across boundaries, more infrastructure to run.
- Re-evaluate per service, not once for the whole system — a system can stay mostly monolith with one or two services split out for a genuine reason.
Practical example
(illustrative). A retailer's monolith ships every two weeks because the payments module, co-deployed with the catalog module, needs a compliance review each release. Splitting payments into its own service lets it deploy on its own cadence (even daily) while catalog keeps its two-week train — the other 90% of the code never needed to split.
When to use it
- Use when: team size or ownership has outgrown one release train, a component has genuinely different scaling or compliance needs, or independent fault isolation prevents one bug from taking down unrelated features.
- Avoid when: one team, unclear boundaries, or the system is young and boundaries haven't stabilized — splitting here just distributes a tangle.
- Failure scenarios: the distributed monolith (services split but still deploying together because they share a database or a chatty synchronous chain) — all the cost, none of the benefit; a premature split based on the org chart rather than data or ownership.
- Simpler alternative: the modular monolith (→ 53) — enforce the same boundaries and ownership discipline inside one deployable; extract a service only when a specific, named pressure demands it.
Practice
(Decision kind — judge 3–5 scenarios and defend the choice; 20 min, no lab services). For each of: (a) a two-person startup building its first product, (b) a 40-engineer company with 5 teams and one shared database already causing merge contention, (c) a single payments module needing independent compliance audits, (d) a reporting job that reads the whole database nightly — decide monolith, modular monolith, or split-out service, and write the one sentence that would change your answer.
Done when every decision names the specific pressure (or its absence) that drove it, not a general preference.
Key takeaway
Microservices are an organizational and operational trade, not a performance feature — they buy independent deployment and scaling, and charge for it in distributed-systems problems. Done when you can: state the specific pressure that justifies a split and defend staying a (modular) monolith when none exists. Used next in → 144 (decomposition), → 145 (boundaries).
References
A pattern language for microservices — see references.md.
Source directory