Guide

Few architecture decisions cause as much argument as "monolith or microservices?" In the 2010s, microservices became the default answer, and teams of eight split their apps into twenty services. By the 2020s the pendulum had swung back. Segment merged more than 140 services into one, and Shopify championed a modular monolith.

Both camps are right about different situations. The useful question is not which architecture is better. It is where the boundaries in your system should go, and how strong each boundary needs to be.

Splitting is mostly an organizational decision. It lets separate teams deploy on their own schedules. It also brings network calls, separate databases and a large operational load.

A sensible default is to start as a modular monolith with enforced module boundaries. Split a module out only when a specific pressure appears: a team that can't ship without waiting on others, a workload that needs different scaling, or a compliance boundary. Each split adds network calls, a database and a deploy pipeline, so every service should earn its place. Shopify's modular monolith is a working example of this approach. The pages below take those ideas in order, starting with the cheapest option that works.

Concepts in this section

StepConceptWhat it answers
1Monolith vs microservicesWhat are the options, and what does each cost?
2Conway's law and team shapeWhy does organization structure drive architecture?
3Bounded contextsWhere should the boundaries go?
4Service communicationShould services call each other, or send events?
5Database per serviceWho owns the data?
6The operational taxWhat must exist before you split?
7Strangler fig migrationHow do you move off a monolith without a rewrite?

Common mistakes

  • Splitting by technical layer. A "validation service" or "database service" means every feature touches every service.
  • Building a distributed monolith. Services that must be deployed together, or share a database, carry all of the cost and none of the independence.
  • Splitting before the boundaries are known. Boundaries become network APIs, which are hard to move. Start with a well-structured modular monolith.
  • Splitting a small team. Twelve services for eight engineers adds operations and no organizational benefit.

Key takeaways

  • Monolith, modular monolith and microservices are points on a spectrum of boundary strength.
  • Microservices are mainly an organizational tool, which Conway's law explains.
  • Draw boundaries around business capabilities, and expect few, coarse crossings.
  • Each service owns its data, and synchronous chains multiply unavailability.
  • Add services when a specific pressure justifies them, and migrate with the strangler fig.

Further learning

Martin Fowler's GOTO talk is a compact tour of what microservices are and when they are worth it.

Microservices • Martin Fowler • GOTO 2014GOTO Conferences
Microservices (Martin Fowler and James Lewis)Microservicesmartinfowler.com Microservices.io patterns (Chris Richardson)Microservices Pattern: A pattern language for microservicesmicroservices.io

Start with monolith vs microservices.