Lesson 04

Failure Across Many Services

Building block

In a fleet, the outage that takes the site down rarely ends where it started. One dependency slows. Every caller holds a worker for each request waiting on it. Their callers time out and retry, and a service with no bug of its own stops answering because it was waiting.

Every service can be built properly, with timeouts, retries and a breaker, and the fleet can still fall over. How one service sets its timeouts, retries, breakers and fallbacks is Backend Deep Dive's chapter on failure. This lesson is about how far one failure spreads across many services, and the few rules held across the whole fleet that stop it.

Slow Is Worse Than Down

A dependency that is down usually fails fast: the connection is refused, or the load balancer has already taken it out, and the caller moves on in milliseconds. A slow one holds resources in every caller for as long as it takes. Assume a service takes 1,000 requests a second that call one dependency, which answers in 50 milliseconds. At any moment, 50 requests are waiting on it.

Now the dependency slows down to its 5-second timeout. The same 1,000 requests a second each wait 5 seconds, so 5,000 would be waiting at once. The service has a pool of 200 workers, and the pool filled long before that. From then on the service fails every request, including the ones that never touch the slow dependency.

Requests in flight are the arrival rate times the time each one is held. That is the arithmetic of the previous lesson's queue, applied to a pool of workers instead of a broker.

One slow dependency fills the shared pool, and the whole page fails
Browseropens the home page Home pageone pool of 200 Accounts50 ms Catalogue50 ms Recommenderslow: 5 s timeout GET /home 5,000 waiting all requests fail readfailure
A slow call against a pool of 200 workers
At 50 ms1,000 requests a second
In flight: 50 of 200. Every request is answered.
At the 5 s timeoutthe same 1,000 a second
In flight: 5,000 wanted, so the pool is full from 200 ms on, and every request fails.

Retries That Multiply

One retry policy is reasonable. The same policy at every layer multiplies. Three attempts at each of three layers is three, times three, times three: 27 calls to the bottom service for one user's request, arriving just when it can least take them.

So the fleet's rule is that one layer retries and the others fail fast, and the layer that retries does so under a retry budget. Assume the budget is a tenth of that layer's traffic. A failing dependency then sees at most a tenth more than its normal load, instead of 27 times its load. Without that rule, a retry storm can keep a system down after its first cause is gone.

The load on a failing bottom service, per user request
Every layer retriesthree layers, three attempts each
3 × 3 × 3 = 27 calls at the bottom for one request. The failing service gets 27 times its load.
One layer, under a budgetretries capped at a tenth of traffic
At most 1.1 times the normal load. The other layers fail fast and pass the error up.

One Deadline for the Chain

Timeouts set hop by hop add up wrong. Say the page has 1 second to answer, and each of three hops below it waits up to 1 second for the next. The bottom hop can still be working after the page has given up, and that work is spent on an answer nobody will read.

So the deadline travels with the request. Each hop receives what the hops above did not spend, checks it before starting, and refuses work it cannot finish in the time left. The cost is that every service reads and forwards the deadline, which makes it a contract across teams rather than a setting inside one service.

Breakers and Bulkheads at Fleet Level

A circuit breaker stops calling a failing dependency. It answers at once with a fallback or an error, and now and then lets a few calls through to test whether the dependency is back. At fleet level its job is to give the dependency room to recover from the whole fleet's load, not only to protect one caller.

A bulkhead gives each dependency its own pool of workers or connections. The slow dependency from the first section then fills only its own pool, and the page keeps answering from the others.

The same page with a pool per dependency and a breaker, the changes marked new
Browseropens the home page Home pagepool per dependencyNEW Accounts50 ms Catalogue50 ms Breakeropen: fails fastNEW Recommenderslow: 5 s timeout GET /home fails at once test calls 200, no recs readfailureNEWsince the shared pool

Scaled up to a fleet, the bulkhead is the cell: independent copies of the whole stack, each serving a slice of the users. A bad deploy, a poison request or one noisy tenant then takes down one cell, not the site. The cost is that each cell keeps its own headroom. The trigger is the point where one failure reaching every user would cost more than all that headroom.

Critical and Optional Dependencies

For every arrow on the diagram, say what the request does when that dependency is slow, down or wrong. A critical dependency fails the request. An optional one is skipped with a fallback: a cached value, a default, or the feature left out, such as a home page without recommendations.

Every dependency taken off the critical path stops counting against the request's availability. The next lesson turns that into a number, and it is usually the cheapest availability in the design.

Retries vs Circuit Breakers

Retries send the call again, and win against a brief fault: a dropped connection, one bad instance. Use them at one layer, inside a budget, for errors a second try can fix.

A circuit breaker stops sending calls, and wins against a sustained failure: a dependency that is down or overloaded. Use it when more calls would only add load to something that cannot answer.

How Interviewers Probe This

A failure probe is answered in three moves: where the failure starts, how far it would spread, and the rule that stops it there.

The classic opener is "The recommendation service gets slow. What happens to the home page?" A good answer does the in-flight arithmetic, sets the call's timeout under the page's deadline, puts recommendations in their own pool behind a breaker, and serves the page without them. You might say: "Recommendations are optional, so they get their own small pool and a breaker. When they're slow, the page goes out without them."

Next comes "Every layer retries three times. Is that a problem?" A good answer multiplies the layers aloud, three times three times three is 27, keeps retries at one layer under a budget, and names backoff with jitter as the half that belongs to each client.

The fleet-wide probe is "A bad deploy reaches every server at once. How do you limit the damage?" A good answer splits the fleet into cells, rolls a change out one cell at a time, and says what headroom each cell keeps.

Misconceptions
  • "Retries make the system more reliable." Against a brief fault they do. Against an overloaded dependency they add load when it has the least room, and at every layer they multiply.
  • "Every call has a timeout, so the caller is safe." A timeout longer than the caller's own deadline protects nothing, and without a cap on waiting requests they still pile up.
  • "A circuit breaker fixes the failing service." It protects the callers and gives the dependency room. The user still gets a fallback or an error, and the design says which.
  • "The health check takes the slow instance out." A check that only asks whether the process answers passes on a slow one. How health checks are built is in Backend Deep Dive.
Why It Matters
  • Retry at one layer only, under a budget capped at a share of its traffic, and let every other layer fail fast.
  • Pass one deadline down the call chain, and let each service refuse work it cannot finish in the time left.
  • Give each dependency its own pool of workers or connections, so one slow dependency can only fill its own.
  • Mark every dependency on the diagram critical or optional, and give each optional one a named fallback.
RelatedBackend Deep Dive one service's timeouts, retries and breakersBackpressure and Load Shedding overload at one tierRegions and the Arithmetic of Nines the critical path as a number

Knowledge Check

A service takes 1,000 requests a second, each calling a dependency. The dependency slows from 50 milliseconds to a 5-second timeout. How many requests wait on it at once?

  • About 50, the same as before it slowed down
  • About 200, which is the size of the worker pool
  • About 5, one for each second of the timeout
  • About 5,000: 1,000 a second held for 5 seconds

Three layers each make up to three attempts on failure. How many calls can one user request send to the bottom service?

  • Three, because only the bottom caller's attempts count
  • Nine, the three attempts added up across three layers
  • Twenty-seven, three times three times three in a row
  • About 1.1 times one call, the normal retry overhead

Why does the deadline travel with the request instead of each hop setting its own timeout?

  • It makes each hop answer faster, because less time is allowed
  • Lower hops otherwise keep working after the page has given up
  • It lets every hop drop its own timeouts and wait without limit
  • Each hop's clock drifts, so local timeouts are never accurate

A dependency has been overloaded and failing for ten minutes. What should its callers do?

  • Retry each failed call three times, with backoff between attempts
  • Raise their timeouts, so the slow answers have time to arrive
  • Open a circuit breaker, answer at once, and test it now and then
  • Add workers in each caller, so more calls can wait on it at once

The fleet is split into cells, each serving a slice of the users. What does that cost?

  • Headroom kept separately in every cell
  • No more deploys to any part of the fleet
  • A consensus round between cells per request
  • Every write copied into all of the cells

You got correct