Microservices vs Monolith — System Design

Monolith = one application, one process, one deploy; modules call each other through almost-free function calls. Microservices = many services with their own…

In a small restaurant, every cook works in one kitchen. Need chilli sauce, just shout, but if the kitchen catches fire, the restaurant closes. In a food court, every stall has its own kitchen and till. The meatball stall can renovate without the food court closing, but meatballs plus iced tea means queueing at two stalls.

Applications can be arranged in these two ways too. A monolith is the restaurant: one application that holds every feature, runs as one process, and is deployed all at once. Microservices are the food court: the application is split into many small services, each with its own code, database and deploy schedule, which talk to each other over the network.

Monolith: one application, one deploy

TicketTune starts as a monolith: one application, app, with the modules account, concert, order, payment and ticket, plus one PostgreSQL database. The order module calls the payment module as a plain function call in the same process: it takes less than a microsecond and can't get "lost on the way".

A tidy monolith is called a modular monolith: each module has its own folder, rules and tables, and other modules only call the functions it opens to them. It's still one deploy, but the boundaries are clear, so it's easy to split later.

Microservices: many small services

In the microservices version, every module becomes its own service: its own process, its own database, its own deploy, usually owned by one team. order may not read the tables that belong to payment; it has to ask through an API (HTTP or gRPC) or send a message through a message queue. The upside: each service can be deployed and scaled on its own. The price: every question between services now crosses the network.

One checkout, five network calls

One checkout touches 5 parts: account (check the login), concert (check the seats), order (create the order), payment (charge the card) and ticket (issue the e-ticket). Example-model numbers: one network call inside the data centre adds 5 ms, and each service (or the monolith) is up 99.9% of the time.

Monolith Microservices
How it calls 5 function calls 5 network calls
Added time almost 0 ms 5 × 5 ms = 25 ms
Checkout succeeds 99.9% (one application) 0.999⁵ = 99.50%
Failures per 10,000 checkouts 10 50
Checkout down per month 43.2 minutes 216 minutes, about 3.6 hours

A checkout succeeds only if all five services are up, so the chances multiply: 0.999 × 0.999 × 0.999 × 0.999 × 0.999 = 0.995. The result is 99.5%: five times as many failed checkouts as the monolith, even though each service is just as reliable.

// TicketTune, example model: the cost of one checkout
const architecture = "microservices"; // "monolith" or "microservices"
const services = ["account", "concert", "order", "payment", "ticket"];
const HOP_MS = 5; // added time of 1 network call
const UPTIME = 0.999; // each service is up 99.9% of the time

const remote = architecture === "microservices";
const addedMs = remote ? services.length * HOP_MS : 0;
const success = remote ? UPTIME ** services.length : UPTIME;

console.log("Added time:", addedMs, "ms"); // 25 ms
console.log("Checkout succeeds:", (success * 100).toFixed(2) + "%"); // 99.50%
console.log("Failures per 10,000:", Math.round((1 - success) * 10000)); // 50

Deploys: who waits for whom

Now from the teams' side. Say each team deploys once a day, and one team's change has a 5% chance of carrying a bug that cancels the deploy (example model). In a monolith, every team's changes ride one deploy, so the deploy is clean only if every team is clean: 0.95 to the power of the number of teams.

Teams Monolith: clean deploy Microservices: clean deploy per team
1 95% 95%
3 85.7% 95%
10 59.9% 95%

With 10 teams in one monolith, 4 deploys in 10 are cancelled because of someone else's bug. With microservices, the payment team can deploy without waiting for the concert team. That's why microservices are often called a fix for a large organisation, not for slow code.

When one part crashes

Say the ticket module leaks memory until its process dies. In a monolith, that process is the only process, so all of TicketTune goes down, the concert page too. With microservices, only the ticket service dies: people can still browse concerts, and checkout fails only at the e-ticket step. This is fault isolation: damage in one part doesn't spread to everything.

When to pick which

Martin Fowler calls this Monolith First: start with a tidy monolith, split when there's a real need.

The extra price of microservices

Once services talk over the network, you need new equipment:

How to build and deploy them is in the Microservices Architecture lesson (DevOps track).

Moving step by step: Strangler Fig

If the monolith really has to be split, don't rewrite everything and swap it in one big launch. Use the Strangler Fig pattern: extract features one at a time into new services while the monolith keeps running. Traffic for that feature moves to the new service gradually, and the monolith shrinks until it can finally be switched off. The full steps are in the Monolith to Microservices lesson.

⚠️ When microservices only make things harder

TL;DR: Monolith = one application, one process, one deploy; modules call each other through almost-free function calls. Microservices = many services with their own code, database and deploy, talking over the network. The price can be computed: a checkout through 5 services at 99.9% each succeeds only 0.999⁵ = 99.5% of the time, and adds 5 × 5 ms. The upside: teams deploy on their own (10 teams in one monolith get 59.9% clean deploys, with microservices 95% per team) and one crashed service doesn't take everything down. Start with a modular monolith while the team is small and the product early-stage (Monolith First), split when there's a real need, and split step by step with Strangler Fig. Microservices bring service discovery, a service mesh (an infrastructure layer for communication between services) and distributed tracing.

⚡ One application or many services

Meaning: A monolith is one application, one process, one deploy. Its modules call each other through almost-free function calls. Microservices split it into many services, each with its own code, database and deploy, talking over the network.

⚡ The chances of failure multiply

Write:

const services = ["account", "concert", "order", "payment", "ticket"];
const UPTIME = 0.999; // each service is up 99.9% of the time
const success = UPTIME ** services.length;
console.log("Checkout succeeds:", (success * 100).toFixed(2) + "%"); // 99.50%
Guess first: each service is up 99.9% of the time. What share of checkouts through 5 services succeed?

99.5%. A checkout only succeeds if all five are up, so the chances multiply: five times as many failures as the monolith.

Meaning: Every network call also adds 5 ms, so 25 ms per checkout.

⚡ The upside: teams deploy on their own

Meaning: 10 teams in one monolith get only 59.9% clean deploys, because one team's bug cancels everyone's deploy. With microservices it's 95% per team. If one service crashes, the others keep running (fault isolation).

⚡ Monolith first

Meaning: A monolith fits better when the team is small, the product is still early-stage, and complexity isn't high yet. Start with a modular monolith, split when there's a real need, step by step with Strangler Fig.

What you will learn