Pointer Walk

Monolith or Microservices

Team size, deploy frequency and whether the parts scale differently: the questions that decide it.

System DesignBeginner8 min read

Two ways to organise a system

Every product is made of parts: orders, payments, email, search. The question is whether those parts live inside one program or in many separate programs that talk over the network.

  • A monolith is one program. All the parts are built together, deployed together and run together.
  • Microservices split the parts into separate small programs. Each has its own code, its own database and its own deploy.

Neither is the modern one or the old one. They trade one kind of difficulty for another.

The same request, both ways

A customer presses Buy. Three things must happen: create the order, charge the card, send a receipt.

Monolith: one checkoutInteractive
Design
Browser
The app
Database

A customer buys something. Follow the request.

Monolith

Monolith: one checkoutInteractive
Browser
The app
Database

A customer buys something. Follow the request.

Inside one program, one part uses another by calling a function. That call takes almost no time, it cannot be lost, and all the changes can be saved in a single database transaction: either everything is saved or nothing is.

Good at

  • Simple to build, test, deploy and debug: there is one of everything
  • Calls between parts are fast and cannot fail halfway
  • One database, so data stays consistent without extra work

Where it bites

  • Everyone changes and deploys the same program, so large teams get in each other's way
  • The whole program scales together, even if only one part is busy
  • One bad bug or memory leak can take everything down

Microservices

Microservices: one checkoutInteractive
Browser
Orders
Payments
Email

A customer buys something. Follow the request.

Now each arrow between services is a trip across the network. It takes milliseconds instead of nanoseconds, and it can time out. In the animation the card was charged and the receipt failed. There is no shared transaction to undo, so the code has to handle being half done. This is the central difficulty of microservices, and it shows up everywhere.

What you get in return is independence. The payments team can deploy ten times a day without asking anyone. Search can run on fifty machines while email runs on two.

Good at

  • Teams build and deploy without waiting for each other
  • Each service scales by itself, on hardware that suits it
  • A failure can be contained to one service, if callers are written to cope

Where it bites

  • Every call between services can be slow or fail, and the code must handle it
  • Data is spread over many databases, so keeping it consistent is your job
  • Much more to run: many deploys, many dashboards, and tracing a request across services

What actually decides it

Microservices are mainly a solution to a people problem, not a technical one. Three questions matter.

QuestionPoints to a monolithPoints to services
How big is the team?A handful of people who all talk to each otherMany teams that cannot all coordinate
How often do you deploy?A few times a week is fineTeams are queueing behind each other
Do parts scale differently?Load is fairly evenOne part needs far more, or very different, hardware

Be honest

Answer for the system you have today, not the one you hope to have.

Monolith or microservices?Interactive

How many engineers work on this system?

Notice where the first question sends most teams. A well-organised monolith carries a company a long way, and it can be split later. Going the other way, merging services back together, is much harder.

Key takeaways

  • A monolith is one program. Microservices are many small ones talking over the network.
  • Inside a monolith, calls are fast and safe, and one transaction keeps data consistent.
  • Between services, every call can fail, and work can be left half done.
  • Microservices mostly solve a team problem: many people needing to deploy independently.
  • Start with a well-organised monolith and split out a part when there is a clear reason.

Your progress

Check your progress

0%

  1. Read the page50% of this page

    When you have gone through the page and its animations, tick it off.

  2. Take the quiz50% of this page

    7 questions, from easy to hard. Take it as often as you like: the questions change, and only your best score counts.

Saved on this device only. See all your progress