Lesson 1 of 17
27. Monolith vs Microservices

The picture to keep in your head

3 min read+10 XP

Every question below is answered twice: first in the restaurant, so you can picture it, then in the system, so you know exactly how it works. Each answer ends with a memory code to lock it in.

The picture to keep in your head

A family restaurant has one kitchen. One menu, one head chef, one set of pots. When the tandoor cook needs paneer, they reach across and take it from the curry station. Fast, simple, and everybody knows everybody. As the restaurant grows, the kitchen gets crowded: cooks bump into each other, and changing one dish means checking with everyone.

A food court works differently. Each stall has its own counter, its own staff, its own pantry and its own opening hours. The dosa stall can change its menu tomorrow without asking the biryani stall. But now there's a directory board so customers can find stalls, a shared seating area to manage, and if your thali needs something from three stalls, you queue three times.

Between the two is a big restaurant with clear stations: one kitchen, but the tandoor, curry and dessert stations each have their own space and their own shelf, and nobody grabs from another station's shelf without asking.

That's this chapter: a monolith, a modular monolith and microservices, and how to choose.

Our running example: the bookstore's backend: catalogue, cart, orders, payments, search and recommendations. It started with 5 engineers and is growing to 60. Latencies and availability figures are assumptions for practice.

In the restaurantIn the system
One kitchen, one menuA monolith: one codebase, one deployable
Everyone grabbing from every shelfTight coupling inside a monolith
One kitchen with clear stationsA modular monolith
A food court of independent stallsMicroservices
Queuing at three stalls for one thaliThe real cost: network calls, failures, operations
Deciding which dishes share a stallDrawing service boundaries
The directory boardService discovery
Ordering at the counter vs a token for laterSync vs async calls
Each stall's own pantryDatabase per service
When to turn a restaurant into a food courtWhen to split

one kitchen, stations, stalls, directory board and pantries mapped to monolith, modular monolith, microservices, discovery and data ownership.

Figure: a food court lets stalls move fast alone, but someone now has to run the whole court.