System Design · 06. Architecture · 10 min · Intermediate

Monolith vs Microservices

One big program or many small ones: what each choice costs and when to split.

In short

A monolith is simple and fast to start: 0.006 ms for a checkout, one thing to run. Microservices give each team its own 5-minute release, and cost 12 ms per checkout, 99.6% uptime and harder debugging.

Draw boundaries along the business, give each service its own data, trace every request, and split only when the pain is real.

Key ideas

  • Good boundaries follow the business, so most changes touch only one service. (step 3)
  • Rule: only the service that owns the data reads or writes it. Everyone else uses its API or its events. (step 6)
  • Start with a monolith, keep modules clean, and extract a service when the pain is real and named. (step 9)

Good to know

  • A monolith is not a mistake. For a small team it is usually the fastest and cheapest way to build. (step 1)
  • Independent deploys are the real prize of microservices. If your services must be released together, you have a distributed monolith: all the cost, none of the gain. (step 4)
  • Many teams get most of the benefit of microservices (clear ownership) with none of the network cost. (step 8)

Watch out

  • The pain is mostly about people: waiting for each other, stepping on each other, and a big blast radius for every mistake. (step 2)
  • The more services a request must pass through, the slower and less reliable it is. Keep call chains short. (step 5)
  • Microservices need logs, metrics and traces from day one. Without them you are guessing. (step 7)
UsersAPI gatewayOrdersPaymentsOrders DBCatalogPayments DBCatalog DB

Key numbers

Release time
5 min
Checkout calls
12 ms
Checkout uptime
99.6%

Terms

Monolith
An application built, deployed and run as a single program.
Microservices
Many small programs, each owning one part of the business, built and released independently.
Domain boundary
A line drawn around one part of the business so a service owns a whole job.
Independent deployment
Releasing one service without waiting for or redeploying the others.
Distributed monolith
Services that must be released together: the costs of microservices without the benefits.
Network call cost
A call between services crosses the network, so it is slower and can fail, unlike a function call.
Database per service
Each service owns its data and others reach it only through its API.
Distributed tracing
Passing one trace id through every service so a whole request can be followed.
Modular monolith
One deployable program built from modules with strict boundaries.