Skip to content
Lesson 30

Monolith or microservices

One app or many small services? Learn what each really costs, the two problems a split can solve, and why most young teams should not split yet.

The lesson in text

Click a paragraph to hear it.

01Twelve services by summer

Monday morning. Karim, StayHub's CTO, walks in with a blog post he printed over the weekend. "Let's split StayHub into twelve microservices," he says. "By summer."

He has two good reasons to be angry. On Friday, a bug in the code that makes invoice PDFs took all four servers down for twelve minutes. About twenty bookings were lost.

And every finished feature waits about three days for a release. StayHub only deploys on Tuesdays and Thursdays, and all three teams share that train.

Would twelve services fix both problems? In this lesson, you'll learn what a monolith and a microservice really are, what a split costs, and how to find the cheapest fix that actually works.

02One kitchen or a food hall

Think of one big restaurant kitchen. All the cooks work in the same room. They share one fridge, they open and close at the same time, and when a dish needs sauce from the next station, they just turn around and ask.

That's a monolith: one app, deployed as one unit, usually with one database. Its parts talk by calling each other directly, inside the same program. It's instant, and a booking and its payment can be saved together, in one go.

Now think of a food hall. Each stall has its own cooks, its own fridge, and its own opening hours. The pizza stall can change its menu without asking the noodle stall.

That's microservices: separate apps, each with its own deploy and its own data. They only reach each other over the network, through an API. Each team ships whenever it likes.

One kitchen or a food hall
Monolith (one kitchen)Microservices (a food hall)
How parts talkDirect calls inside one program: instant, can't half-failOver the network, through an API: can be slow or fail
ReleaseOne deploy for everyoneEach service ships on its own
DataUsually one database; a booking and its payment saved togetherEach service owns its data; no saving across services in one go
To runOne pipeline, one set of dashboardsA pipeline, dashboards and on-call per service
FitsOne or a few teams, product still changingMany teams with clear business areas, and a platform to carry the tax
The food hall buys independence for each stall. It pays for it with runners between stalls on every order.

But a full meal now needs runners between stalls. And when the pizza stall is slow, the whole tray waits. Keep that picture: it's the price of the food hall.

03Two different problems

Look closely at Karim's two complaints. They're not the same kind of problem.

The three-day wait is a team problem: three teams share one release, so they wait for each other. Separate deploys can fix that, but only if the teams really work on separate parts.

The crash is an isolation problem: the PDF code runs in the same programs that serve guests. When it ran out of memory, it took search and booking down with it. That needs a wall between the risky work and the guests, not twelve services.

04Isolation without a network

Back in the kitchen. The grill fills the room with smoke, so you give it its own room, with its own door. Same restaurant, same cooks, same menu. If the grill catches fire, the rest of the kitchen keeps cooking.

Lina does exactly that. She runs the PDF and email jobs in a separate worker: the same code, started as its own program, picking jobs from a queue. The four servers that answer guests never run PDF code again.

Isolation without a network
Web (4 servers)
behind the load balancer
search · booking · login
queue →
Worker (2 processes)
same code, started in worker mode
invoice PDFs · emails
Same repo, same release, two kinds of program. The web servers put jobs on a queue and never run PDF code. If the PDF code leaks memory again, a worker restarts and guests don't notice.

If the leak comes back, a worker crashes and restarts. Guests don't notice. No new repo, no new pipeline, no network in between. And she writes down when to go further: extract invoicing when a team of its own owns it.

05The network tax

Why not just split anyway? Because every call that used to happen inside one program now crosses the network, and the network has a price. Engineers call it the distributed-systems tax.

A call can be slow. It can fail halfway. It can be retried, and if it was a payment, the guest is charged twice unless you planned for it. And you can no longer save a booking and its payment together, in one go.

Then each service needs its own pipeline, its own dashboards and someone on call. For fourteen engineers, twelve services means almost one service per person to run, forever.

Even uptime gets worse. If one booking needs five services in a row, and each is up 99.9% of the time, the whole chain is up only about 99.5%. That's forty-three minutes of downtime a month becoming more than three and a half hours.

Services in a row: uptime multiplies
Services in the chainWhole chain upDown per month
199.9%about 43 minutes
299.8%about 1.4 hours
399.7%about 2.2 hours
599.5%about 3.6 hours
Every service in the chain must be up at the same time. Each one at 99.9%, five in a row: 0.999 × 0.999 × 0.999 × 0.999 × 0.999 ≈ 0.995. Downtime per 30-day month.

And Karim's other argument, that services scale better? StayHub already runs four copies of the monolith, at about a third of their capacity. A monolith scales by running more copies. The real limit is the database, and splitting the code doesn't make it faster.

06Slow is worse than dead

StayHub has already tried one service. Last month, the Search team moved pricing out into its own service. The monolith asks it for a price for every hotel on the page, and waits for the answer.

One Wednesday afternoon, pricing slowed from 40 milliseconds to 9 seconds. Nobody had set a time limit, so every page waited. Waiting requests piled up until all four servers were full, and the whole site stopped answering. Login and booking too.

Slow is worse than dead
No timeout
Guest
Monolith
Pricing service
show me hotels in Lisbon
price for each hotel card?
… 9 seconds later
servers full: the site stops answering
Timeout, fallback, circuit breaker
Guest
Monolith
Pricing service
show me hotels in Lisbon
price? (give up after 300 ms)
page with yesterday's cached prices
Without a time limit, each page holds a server connection for 9 seconds. Within minutes all four servers are full and login and booking stop too. With a 300 ms timeout and cached prices, the page answers anyway.

A dead service fails fast, and you move on. A slow one holds everyone hostage. It's the pizza stall that never says no, so every tray in the hall waits for it.

So every network call needs three things: a timeout, a short time limit like 300 milliseconds; a fallback, like yesterday's cached price; and a circuit breaker, which stops calling a service that keeps failing, and tries again later.

07When a split pays

Splitting does pay, in the right place. In 1968, Melvin Conway noticed that systems end up shaped like the teams that build them. That's Conway's law. Services work when each one belongs to one team, along a business area like payments, not a technical layer.

Big companies with hundreds of engineers split for that reason: so each team can ship alone. But in 2023, a Prime Video team went the other way. Its tool's parts passed data to each other all day, so they merged them into one program and reported cutting the cost by over ninety percent.

The worst result is a distributed monolith: services that still share one database and still deploy together. You pay the whole network tax and get none of the independence.

So before any split, ask four questions. Does a team of its own own it? Is its work very different, like heavy PDFs? Does it need to be isolated? And is its boundary stable, or does it change with every feature?

Before any split: four questions (example: invoicing)
QuestionAskInvoicing at StayHub
Its own teamIs it owned by a team that is blocked by the shared release?Booking owns invoices: no
Different workDoes it need very different resources, like heavy PDFs?Yes
Needs isolationMust its failures stay away from guests?Yes
Stable boundaryDoes its interface rarely change?No: invoices change with every pricing feature
A service earns its network tax only when several answers are yes at once. Here the two yeses are the same need, isolation, and a worker gives it for less.

For StayHub, with fourteen engineers, the answer is one app with strong walls inside, which is the next lesson. Revisit if a team is blocked more than once a week, or when StayHub nears forty engineers.

08Your job as lead

Ask Claude Code to make invoices stop taking the site down, and it may propose a lot. A new invoicing service with its own repo. The monolith calling it after every booking. The service reading the bookings table directly. Both deployed together, on Tuesdays and Thursdays.

Read that plan again. A shared table, deploys in lockstep, and a new call that can fail. That's a distributed monolith. Reject it, and ask for a worker that runs from the same code instead.

When a new service does make sense, ask three questions. Which team owns it, and which data does only it touch? What's the timeout on every call to it? And what does the guest see when it's down?

Let's recap. A monolith is one kitchen: one deploy, instant calls, one database. Microservices are a food hall: independent stalls, paid for with a network tax on every call. Split for teams or isolation, never for fashion, and often a worker gives you isolation for free. Next: how to build strong walls inside one app.

Check yourself

0/10 answered
  1. 1What is a monolith?

  2. 2In the food hall picture, what is the cost of separate stalls?

  3. 3Invoice PDF code ran out of memory and took all four servers down. What's the cheapest fix that works?

  4. 4Features wait three days for a release because three teams share one deploy. What kind of problem is that?

  5. 5One booking calls five services in a row, each up 99.9% of the time. Roughly how available is the whole chain?

  6. 6Users see the whole site freeze, login included. The pricing service slowed from 40 ms to 9 s, and the monolith calls it with no time limit. What was missing?

  7. 7Two "separate" services read and write the same bookings table and always deploy together. What is this?

  8. 8Karim says microservices scale better. StayHub runs four copies of the monolith at about a third of their capacity. Why is the argument weak here?

  9. 9Claude Code plans a new invoicing service that reads the bookings table directly and deploys with the monolith every Tuesday and Thursday. What do you do?

  10. 10Which question best tells you whether a part should become its own service?

Free account

Save your progress — create a free account

Free. No card. Your finished lessons follow you to any device, and you can ask questions in the community.

Create my free account
Founding members

Every lesson is free while we build. Lock in €9/month for later.

The first 100 members keep the founding price for as long as they stay. Reserving is free: no card, nothing is charged.

See the founding offer

Questions from the community

All questions →