Split one request across 10 services that are each up 99.9% of the time, and about 1 request in 100 fails instead of 1 in 1,000. In return, ten teams can each ship on their own day.
Pick a shape for the request and drag the number of steps. Watch the failures and the slowest requests grow. Then we build, piece by piece, the release train, the multiplying hops, the boundaries, the gateway, the tail, the mesh and the migration.
You need what an HTTP request is and what a probability is. Service Communication helps. We build the rest from zero.
Simulated in your browser, 100,000 requests per shape, one fixed seed. Illustrative: each step does 1 ms of work on average; each network call adds 0.5 ms, and 1 call in 200 stalls for 50 ms; each process is up 99.9% of the time, independently. Chapters 0, 2 and 5 work each number.
Chapter 0
Put every team's change in one release, then watch one bad change send them all back
A shop runs as one program: accounts, cart, pricing, payments and search in one codebase, built and deployed as one unit. Five engineers ship it twice a day. Then the company grows to fifty engineers in ten teams.
Now every release carries ten teams' changes. If one change breaks a test or an alert after the deploy, the whole release rolls back, and nine good changes wait for tomorrow. Nothing about the servers changed. The program's shape now fights the way the people work.
How often does a release roll back? Call the number of teams with a change in the release k, and the chance that one change is bad f. Call the chance that the release rolls back Proll.
P-roll equals one minus, one minus f, to the power k.
One change is good with chance one minus f. All k changes are good with that chance multiplied k times. Take that from one, and you have the chance that something in the release is bad.
With made-up numbers: f = 0.05, k = 10. 0.9510 = 0.599, so Proll = 0.401. Four releases in ten go back. A good day ships all 10 changes, so the average is 10 × 0.599 = 6.0 changes a day. Teams that deploy alone ship each good change: 10 × 0.95 = 9.5.
Each row is a day; each square is one team's change. Red is a bad change. In one release, a red square sends the whole row back to pink. Drag the teams and the bad-change rate, then switch to separate deploys.
Simulated: 2,000 release days, one seed, one change per team per day, each bad with chance f, independently. The grid shows the first days. Illustrative rates, not measurements.
Splitting the program lets each team deploy alone. It also moves the same multiplication somewhere else: from the release to every live request. That trade is this lesson.
Failure. Symptom: deploys drop from twice a day to twice a week as the team grows. Measure: the share of releases rolled back, and changes waiting per release. Cause: one bad change blocks every change in the same release. Fix: smaller releases, tests that isolate each part, or parts that deploy alone.
Chapter 1
Keep everything in one process, then watch shortcuts between modules spread every change
A monolith is one deployable unit that holds the whole application: one codebase, one build, one process image. When the cart needs a price, it calls a function in the pricing module. That call stays inside one process. It costs well under a microsecond.
That gives the monolith real strengths. One database transaction can cover the cart and the order together. One stack trace shows the whole path of a request. Your editor can rename a function and fix every caller. And there is no network to fail between two modules.
The worked number. A page makes 20 calls between modules. In one process, 20 calls cost a few microseconds in total. Inside one data centre, a network round trip takes about 0.5 ms (illustrative). The same 20 calls in a row then cost 10 ms. That is thousands of times more, before any call fails.
The monolith's weakness is coupling: modules that depend on each other's insides. A deadline comes. Payments reads the orders table directly instead of asking the orders module. Each shortcut is small. Together they mean a change to one module can break modules that never called it.
Orange boxes are modules. Blue arrows are calls through a module's public interface; dashed arrows are shortcuts into its insides. Pick a module to change: the pink modules need a retest. Then add shortcuts.
Illustrative: six modules, five interface calls and a fixed list of six shortcuts. "Retested" counts every module that depends on the changed one, directly or through others.
With clean interfaces, a change forces retests in 1.2 modules on average. After four shortcuts, it is 4.2: every module except Search. The fix need not be services. A modular monolith keeps one deployable unit but lets the build reject calls into another module's insides. Shopify chose this path for its main codebase, with boundaries between components that tooling enforces.
Failure. Symptom: a small change to pricing breaks the payments page. Measure: which modules import another module's internal classes or tables. Cause: shortcuts around public interfaces. Fix: declare each module's interface and fail the build on any other import.
Chapter 2
Split the program into services that deploy alone, then multiply their availabilities along the path
Lewis and Fowler (2014) describe microservices as one application built as a suite of small services. Each runs in its own process and talks to the others over the network. Size is not the test. Two properties are:
The price shows up on every request. A checkout that crosses several services succeeds only if every one of them answers. Call the share of time service i is up ai, the number of services on the path n, and the share of requests that get through Apath.
A-path equals a-one times a-two, and so on, times a-n.
Multiply the up-share of every service the request must reach. Each factor is below one, so every service you add pulls A-path down. This holds when the services fail independently.
With made-up numbers: ten services, each a = 0.999. Apath = 0.99910 = 0.990. Failures rise from 1 in 1,000 to about 10 in 1,000. Over a 30-day month, 0.1% is 43 minutes; 1% is 430 minutes.
Each orange box is a service on the checkout path. Blue requests travel right; a red mark is a request that died at that service. Pick how reliable each service is and how many the path crosses.
Simulated: 200,000 requests, one seed; each service fails a request with chance 1 − a, independently. The moving dots fail 30 times more often so you can see them; the counts use the true rate. Illustrative rates. Real failures are often correlated, which can make it better or worse.
Two things soften the product. A call the page can do without, like recommendations, can fail with a fallback instead of failing the page (Chapter 9). And a service that runs many copies can retry on another copy (Chapter 6). Neither is free.
Failure. Symptom: every service meets its 99.9% target, yet checkout fails 1% of the time. Measure: success rate of the whole user request, end to end. Cause: availabilities multiply along the path. Fix: fewer services on the critical path, fallbacks for optional calls, and retries on another copy.
Chapter 3
Try three ways to split a checkout, and count the network calls and the shared releases each one costs
The hard question is where to cut. Cut well, and most features change one service. Cut badly, and each request makes many network calls and each feature waits on three teams. That is worse than the monolith.
Domain-driven design gives the main tool: the bounded context, a part of the business inside which each word has one meaning. "Product" in the catalog is a name and photos. In shipping, it is a weight and a box size. Each context owns its model and its data, and is a good candidate for one service.
Each chip is a part of the code; an orange outline is one service. Thick blue arrows cross a service boundary, so they become network calls. Pick a split.
Illustrative: one checkout makes the calls drawn (3 items in the cart), at 0.5 ms per network call; five sample features list the parts each one changes. Counted by the same code that draws the chips.
By layer, a checkout makes 10 network calls, and the average feature changes 2.6 services. By domain, it makes 5 calls and changes 1.6. Too fine gives 18 calls and 2.8. Chatty calls and shared releases both say the cut runs through one context.
The cut also follows the people. In 1968, Melvin Conway argued that an organisation which designs a system produces a design that copies its own communication structure. Fred Brooks counted the cost of that talk: with n people who must each coordinate with each other, the paths between them are:
Paths equals n times, n minus one, over two.
Each of the n people pairs with the n minus one others. That counts every pair twice, so halve it. Paths grow with the square of n.
Fifty people in one group: 50 × 49 / 2 = 1,225 paths. Split into 8 teams (two of 7, six of 6) that meet through one interface each: 2 × 21 + 6 × 15 = 132 paths inside teams, plus 8 × 7 / 2 = 28 between teams. That is 160 in total.
Failure. Symptom: every feature needs a planning meeting with three teams. Measure: services changed per feature, and calls between services per request. Cause: boundaries cut through one bounded context, or across team lines. Fix: merge the chatty services, or move the boundary so one team owns the whole context.
Chapter 4
Send the phone's calls through one gateway, and pay the slow mobile round trip once instead of four times
The app's home screen needs the user, their orders, recommendations and notifications: four services. If the app calls each one itself, it must know every service's address and API. Every new service means an app update. And each call crosses the slow mobile network.
An API gateway is one entry point for all clients. It checks the login token once, applies rate limits, and routes each path to its service. It can also aggregate: take one request from the phone, call four services at once inside the data centre, and return one answer.
How long does the phone wait? Call the mobile round trip Rm, the number of services k, and the time service i takes inside the data centre ti. Through the gateway, the phone waits Tgw.
T-g-w equals R-m plus the largest of t-one up to t-k.
The phone pays one mobile round trip R-m. Inside, the gateway starts all k calls together and waits for the slowest t-i. If the phone called the services one after another, it would pay R-m plus t-i for every service.
With made-up numbers: Rm = 80 ms, t = 4, 6, 5, 9 ms. Tgw = 80 + 9 = 89 ms. One call after another: (80 + 4) + (80 + 6) + (80 + 5) + (80 + 9) = 344 ms.
The bars are a timeline: yellow is time on the mobile network, orange is time inside the data centre. Pick how the phone calls, then drag the services and the round trip.
Illustrative times: services take 4, 6, 5, 9, 7, 3, 8 and 5 ms in that order; connections are already open; the toy leaves out the gateway's own hop. A new connection costs more round trips for TCP and TLS (see Network Foundations).
Calling all four at once also costs about one round trip. But the phone then holds a connection to each service and knows every address. One gateway per kind of client is the backend for frontend (BFF) pattern. Phil Calçado named it and Sam Newman wrote it up. The mobile team owns the mobile BFF and shapes its answers for the phone.
Failure. Symptom: the whole app is down though every service is healthy. Measure: gateway errors and its CPU. Cause: one gateway is a single point of failure for all clients. Fix: several gateway copies behind a load balancer, and cached or partial answers when one service fails.
Chapter 5
Fan one request out to many servers, and watch a rare slow answer become the common case
A search page asks 100 servers at once, each holding a slice of the index, and waits for all of them. Each server answers in 10 ms almost always. But 1 time in 100, a server stalls: a garbage collection, a busy disk, a noisy neighbour. Then it takes a full second.
Dean and Barroso worked this example in "The Tail at Scale" (2013). How often is the whole page slow? Call the chance that one server is slow p, the number of servers the request waits for n, and the chance that the request is slow Pslow.
P-slow equals one minus, one minus p, to the power n.
One server is fast with chance one minus p. All n are fast with that chance multiplied n times. Take that from one: the request is slow when any single server is slow.
The paper's numbers: p = 0.01, n = 100. 0.99100 = 0.366, so Pslow = 0.634. 63% of requests take over a second. With p = 1 in 10,000 and n = 2,000: Pslow = 0.181, almost one in five.
This is Chapter 0's formula again. There, one bad change spoiled a release. Here, one slow server spoils a request. Google measured it on a real service: a single leaf finished within 10 ms at the 99th percentile, but waiting for all leaves took 140 ms.
The yellow curve is the formula against n. The grid shows one request's servers: yellow squares are slow, and teal ones were slow until a hedge answered. Pick p and n, then turn on hedging.
Simulated: each server answers in 10 ms, or 1,000 ms with chance p, independently. A hedge sends a second copy to another replica after 20 ms and keeps the first answer. Up to 4,000 requests per setting, one seed.
The paper's fixes target the tail, not the average. A hedged request sends a second copy if the first has not answered after a short delay. In a Google benchmark reading 1,000 keys from 100 BigTable servers, hedging after 10 ms cut the 99.9th-percentile latency from 1,800 ms to 74 ms, for 2% more requests.
Failure. Symptom: each service's p99 looks fine, yet the page's p99 is ten times worse. Measure: the latency of the whole user request, and how many calls it waits on. Cause: with fan-out, the slowest answer sets the time. Fix: fewer calls on the path, hedged requests, and answers that can come back without the slowest leaf.
Chapter 6
Move retries, timeouts and encryption out of the code into a sidecar proxy, and count the CPU it costs
Every service needs the same plumbing for its calls: timeouts, retries, encryption between services, load balancing over copies, and metrics. Thirty services in four languages means four libraries to write and keep in step. Change the retry policy, and thirty services must rebuild.
A sidecar is a helper process that runs next to the app, starts and stops with it, and shares its network. A service mesh puts a proxy sidecar beside every service. The app sends a plain request to its local proxy. The proxy encrypts it with mTLS (both ends prove who they are), sends it to the other service's proxy, retries on failure, and records metrics.
In Istio, the sidecar is Envoy, and Istio adds it to each pod by a Kubernetes admission webhook. Linkerd uses its own proxy, written in Rust. Kubernetes gained native sidecar containers in v1.28; they are stable since v1.33.
The proxies cost CPU. Call the requests per second entering the system r, the service-to-service hops per request h, and the CPU one proxy spends per request per second cp. Each hop passes two proxies: the caller's and the callee's.
CPU-mesh equals r times two h times c-p.
Count proxy passes per second: r requests, each with h hops, each hop through two proxies. Multiply by the CPU one pass costs, c-p.
r = 10,000, h = 5, cp = 0.0002: 10,000 × 10 × 0.0002 = 20 vCPU. Memory adds up too: at the docs' 60 MB per sidecar, 200 pods hold 12 GB of proxies.
Orange boxes are services; small boxes beside them are their proxies. A blue request lights each proxy it passes. Drag the hops and the request rate.
CPU per proxy pass from Istio's performance page (Istio 1.24, 0.20 vCPU per 1,000 requests a second). Added latency uses 0.25 ms per proxy pass, illustrative: measure your own. Library CPU is not zero, but it runs inside the app.
Istio's newer ambient mode, generally available since Istio 1.24, drops the sidecar. A shared proxy on each node, ztunnel, does mTLS and L4 work. An optional waypoint proxy does L7 routing only where you need it.
Failure. Symptom: a slow service suddenly gets three times its normal traffic, then falls over. Measure: retries per call, at every layer. Cause: retries at several layers multiply: three tries at each of three layers is 27 calls. Fix: retry at one layer, with a retry budget and backoff (Resiliency Patterns).
Chapter 7
Crash the control plane, and watch the proxies keep routing on the last rules they received
A mesh has two parts. The data plane is the proxies: they carry every request, so they must be fast. The control plane decides the rules, such as which copies exist, where 10% of traffic goes, and which certificates are valid. It pushes those rules to the proxies. It never carries a user request.
In Istio, the control plane is istiod, and the data plane is the Envoy proxies. Envoy receives its configuration over the xDS APIs: listeners, routes, clusters and endpoints. The same split appears in Kubernetes. The API server and controllers decide what should run, and the kubelet on each node runs it.
The split decides what breaks. Envoy's xDS protocol says that if the management server is unreachable, the last configuration Envoy received stays in place until the connection comes back. So traffic keeps flowing. But nothing changes either: new pods are not added and dead pods are not removed.
The orange box on top is the control plane; purple tables are what each proxy believes. Blue requests flow below. Crash the control plane, then replace a pod, and watch who still sends to the old one.
Illustrative: four pods, three proxies, requests spread evenly. When the control plane is up, a new table reaches every proxy at once; real pushes take time. Retries and outlier ejection, which would hide some errors, are off here.
The worked number, illustrative. A fleet runs 200 pods, and deploys replace each pod about once a day. That is 200 / 1,440 = 0.14 pods a minute. During a 30-minute control plane outage, deploys replace about 4 pods, and every proxy still sends a share of traffic to their old addresses.
Failure. Symptom: errors to a few addresses grow slowly while the control plane is down, and a rollout seems to do nothing. Measure: config age at each proxy, and pushes that failed. Cause: the data plane runs on frozen rules. Fix: run several control plane copies, alert on config age, and keep retries and outlier ejection on in the proxies.
Chapter 8
Put a facade in front of the monolith, then move one route at a time behind a small canary
You decide to split the monolith. The tempting plan is a rewrite: freeze features, build the new system, switch over one night. Fowler warns against this big-bang replacement, and argues for a gradual one. Big rewrites tend to run long, and the old system keeps changing while you build.
Fowler named the gradual pattern the strangler fig, after the vines he saw in Queensland. A strangler fig grows around a host tree until the fig stands on its own. In software, you put a facade, usually a proxy or the gateway, in front of the monolith. Every route passes through it.
/admin.The facade on the left sends each route to the monolith or to new code. Bars show each route's share of traffic. Move a route, drag its canary share, and try a bug in the new code.
Illustrative: 10,000 requests a second split over six routes as shown; the monolith fails 0.1% of requests, buggy new code 2%. Routes move from the least traffic to the most.
The worked number, illustrative. The checkout route's new code has a bug that fails 2% of requests, and checkout carries 10% of 10,000 requests a second. At a 5% canary: 10,000 × 0.10 × 0.05 × 0.02 = 1 failure a second, which you can spot and roll back. Switched to 100% at once: 20 failures a second.
Moving routes in this order, from little traffic to most, puts 10% of traffic on new code after two steps and 35% after four. Each step is small enough to undo, which is the point.
Failure. Symptom: the migration is "80% done" for two years. Measure: traffic share on new code per quarter, and old code deleted. Cause: the hard routes share tables with everything, and new features keep landing in the monolith. Fix: move the data with each route, and send new features to the new side only.
Chapter 9
Run one checkout as a monolith, as services, or as services in a mesh, then crash, slow and rescue it
One checkout page. The gateway asks the user, cart and recommendations services at once. Then it asks pricing, then payments. Recommendations is the only optional call. The read-out runs 40,000 checkouts for each setting.
Blue requests leave the gateway; teal answers come back. A red service has crashed. Pick an architecture, then break things and watch the success rate and the slowest checkouts.
Simulated: 40,000 checkouts per setting, one seed. Illustrative: work of 1, 1, 2, 1 and 3 ms; 0.5 ms per network call with 1 in 200 stalling 50 ms; each copy up 99.9%; the mesh adds 0.25 ms per proxy pass and retries a failed call once on another copy. In the monolith, a crash takes the shared process down.
Things to try:
The worked number: services and a fallback, with recommendations crashed, still complete 99.7% of checkouts. The monolith completes none, because one module's crash is the whole process's crash.
Failure. Symptom: a crashed optional service takes the whole page down. Measure: which calls the page needs, and which it can skip. Cause: the page treats every call as required. Fix: a fallback and a short timeout for each optional call, so the page degrades instead of failing.
Chapter 10
Keep the numbers, the choices and the code for the next time someone asks to split a system
Services solve a people problem: many teams blocked in one release. They pay for it on every request, because availabilities multiply along the path and the slowest of many answers sets the time. Cut along bounded contexts and team lines. Put a gateway at the edge, consider a mesh inside, and migrate one route at a time.
| Term | What it is | This lesson's number |
|---|---|---|
| Release rollback | Proll = 1 − (1 − f)k | f 5%, k 10: 40% of releases |
| Path availability | Apath = a1 · … · an | 0.99910 = 0.990 |
| Communication paths | n(n − 1) / 2 | 50 people 1,225; 8 teams 160 |
| Gateway wait | Tgw = Rm + max ti | 89 ms against 344 ms |
| Fan-out tail | Pslow = 1 − (1 − p)n | p 1%, n 100: 63% |
| Mesh CPU | cpumesh = r · 2h · cp | 10,000/s, 5 hops: 20 vCPU |
| Canary blast | rate × route share × canary × error | 1 failure/s against 20 |
| Situation | Shape | Why |
|---|---|---|
| One team, new product | monolith, modular inside | boundaries are unknown yet; Fowler's "Monolith First" |
| Many teams, one release train | services by bounded context | each team ships alone |
| Many clients on slow networks | gateway or one BFF per client | one round trip, one door |
| Many languages, same plumbing | service mesh | one proxy, one policy |
| A legacy monolith to replace | strangler fig behind a facade | small steps, each undoable |
python# the three products of this lesson, checked by simulation import random def any_bad(n, p, trials=200_000, seed=1): """share of trials where at least one of n independent parts goes wrong""" rnd = random.Random(seed) hits = sum(any(rnd.random() < p for _ in range(n)) for _ in range(trials)) return hits / trials for name, n, p in [("release rollback", 10, 0.05), # formula 0.401 ("path failure", 10, 0.001), # formula 0.00995 ("slow fan-out", 100, 0.01)]: # formula 0.634 print(name, round(any_bad(n, p), 4), round(1 - (1 - p) ** n, 4))
Now press Present or Teach and explain four things from memory. Explain why ten teams in one release roll back 40% of the time. Explain why ten services at 99.9% give 99.0%. Explain why fan-out to 100 servers makes 63% of requests slow. Explain why a fallback saves the checkout when retries cannot. Then go back to the hero, pick Chain, and drag the steps from 1 to 12.