Cascading failures: when one loss becomes all of them
A failure that feeds itself
Section titled “A failure that feeds itself”The shop in this module has a load balancer, three API instances, a cache and a database, and 900 requests arrive each second. Each instance runs 8 requests at once and takes 20 ms for each, so one instance serves 8 ÷ 0.020, which is 400 requests a second, and the three serve 1,200. At 900 the API is at 75% of what it can do. That is comfortable.
Now one instance dies. The two that remain serve 800, and 900 keep arriving. The API has 113% of the work it can do (the lab rounds 112.5% to 113%). The shortfall is only 100 requests a second, which is 11% of the traffic. You might expect about 11% of the requests to fail.
Google’s SRE book describes why it does not. A cascading failure is a failure that grows through positive feedback: the first failure raises the probability of further ones. Its commonest cause is the one in this shop: when part of a service fails, the load moves to the part that is left, which makes that part more likely to fail. The book names resource exhaustion and retries without safeguards as the other fuel.
Mental model. A cascade is a loop. Less capacity means more work per remaining server, which means longer waits, which means timeouts, which means wasted work and more retries, which means less useful capacity again. Each turn of the loop makes the next one worse.
Try it: kill one of three
Section titled “Try it: kill one of three”Before you press the button, write down what share of requests you expect to fail. Then press Kill an API instance, read the cause-and-effect chain, and look at the charts.
Kill an API instance
The shop serves 900 requests a second. Three API instances can serve 1,200 a second, so the system is comfortable. You kill one instance. The two that remain can serve 800. Watch the queue, the latency and the requests, then decide what you would have built differently and run the same failure again.
The failure lab needs JavaScript. The healthy system is shown below.
1. Break it
The healthy system is shown first. When you press the button the failure strikes, and the run follows the 30 seconds after it.
What the failure does: One of the three API instances stops. The load balancer sends all the traffic to the two that remain.
Each dot stands for many requests. The numbers show the real rate.
No bottleneck: every component has headroom.
Cause and effect
Each step leads to the next. A step that is changing right now is marked.
- Traffic900 req/sNormal steady
- API utilisation75%Normal steady
- API queuenone waitingNormal steady
- Latency (p99)96 msNormal steady
- Timeouts and rejections0%Normal steady
- Errors0%Normal steady
| Component | State | Utilisation | Offered (req/s) | Served (req/s) | Rejected (req/s) | p50 | p95 | p99 |
|---|---|---|---|---|---|---|---|---|
| Clients | Healthy | <1% | 900 | 900 | 0 | 0 ms | 0 ms | 0 ms |
| Load balancer | Healthy | <1% | 900 | 900 | 0 | 0.03 ms | 0.15 ms | 0.23 ms |
| API | Busy | 75% | 900 | 900 | 0 | 14 ms | 60 ms | 93 ms |
| Cache | Healthy | 1% | 810 | 810 | 0 | 0.14 ms | 0.6 ms | 0.92 ms |
| Database | Healthy | 20% | 252 | 252 | 0 | 5.5 ms | 24 ms | 37 ms |
- Traffic
- 900 req/s
- Successful
- 900 req/s
- Error rate
- 0%
- Mean latency
- 24 ms
Sources
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Requests arrive at random, as a Poisson process, at a constant average rate.
- Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
- Service times are random with the stated mean; by default they are exponentially distributed.
- Each node is analysed separately, with the traffic it receives treated as Poisson.
- The system starts healthy at 900 requests a second. Three API instances can serve 1,200 a second and the database about 1,250 operations a second. Nine in ten requests read through the cache, which answers four in five of those reads; the rest, and every write, go to the database.
- A failure strikes at one instant and nothing repairs it during the run: no restart, no autoscaling, no operator. The load balancer notices a dead instance at once.
- The instances of a component are identical, and each request is independent of the others.
Simplifications
- Nothing brings the instance back during the run: no restart and no autoscaling, which in practice replace an instance after a delay. You see the failure at its full length.
- The load balancer notices the dead instance at once. In practice there is a window in which it still sends requests to it.
- A retry is a fresh, independent attempt with the same chance of failing as the last one. How long a real client library waits between attempts (backoff, jitter), and any retry budget or circuit breaker, are not simulated: attempts are counted, not scheduled.
- A client gives up when its first timeout runs out, so the latency shown stops at what a client would wait: the timeout of the first hop, times its attempts. After that the request counts as a failure.
- The cache's hit ratio is constant. Warming, stampedes and hot keys have their own labs.
- Nothing here models garbage collection, connection pools on the client, DNS, TLS handshakes, CPU throttling, noisy neighbours or cold caches. A real system fails in more ways, and in messier ones, than this model does.
- Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
- Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
- A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
- A request calls its dependencies one after another. Parallel fan-out is not modelled.
- When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
- Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
- A caller’s timeout counts the mean time its dependencies take, not their full distribution.
- Latency percentiles for a whole request are estimated, over every request, including those that are rejected and fail quickly. The mean is exact, and the percentiles come from a gamma distribution that has that mean and the variance of the time spent in each component.
Parameter values are illustrative. They are not benchmarks of any real product.
Read the chain from the top. Utilisation of the API goes from 75% to 113% in the first quarter of a second. Requests waiting at the API go from none to 1,000, which is the queue limit, and that step is critical after 5 s. The time a request takes climbs until it reaches 1 s, the longest the load balancer will wait. Attempts refused or too late become critical after 7.5 s, and requests that fail go from 0% to 100%, critical after 8.25 s.
Over the 30 seconds after the failure, 71% of the requests fail on average. The chart shows the shape: for the first 6 s nothing fails, because the queue is absorbing the 100 requests a second the API cannot do, and a queued request that is served in under a second is still an answer. After 8 s the queue holds 800 requests, and a request that joins it waits 800 ÷ 800, which is 1 s, the longest the load balancer will wait. From then on the answers arrive too late to count. The API still serves them, one after another, in the order they arrived, so the work it does is for requests that have already given up. Eventually almost nothing it serves is in time.
This is the part that surprises people. The API still has 800 requests a second of capacity, and 900 are arriving, and yet it answers nobody in time. Google’s chapter on handling overload says what a healthy server should do instead: keep accepting traffic up to its capacity, and no more than it frees up. Amazon’s engineers describe the loop: when a server is past its capacity the clients time out, and all the progress the server made on those requests is wasted. Waiting in a queue is not free. It turns a shortage of 11% into a total loss.
What spare capacity, cheaper work and a deadline each do
Section titled “What spare capacity, cheaper work and a deadline each do”Choose the changes and press Run the same failure again with these changes. Remember that the lab applies a fix from the start of the run, as if you had built it before the failure, and not as a reaction to it.
| Change | Requests that fail | Busiest component | Time a request takes (p99) | Price |
|---|---|---|---|---|
| None | 71% | 113% | 1 s | None |
| Run a spare instance | 0% | 75% | 96 ms | A fourth instance, idle most of the time: a third more than three |
| Make each request cheaper | 0% | 84% | 77 ms | Engineering time, and the saving can be eaten by tomorrow’s traffic |
| Shed load: drop requests that waited too long | 10% | 113% | 402 ms | No capacity added: the excess is refused |
The spare instance is the arithmetic of N+1: with four instances, the three that remain still serve 3 × 400, which is 1,200, more than the 900 that arrive. Making each request cost 15 ms instead of 20 gives each instance 8 ÷ 0.015, about 533 requests a second, so the two that remain serve about 1,067 and the API runs at 84%. Both remove the overload.
The deadline does something different. It adds no capacity, so the API is still at 113%. It drops a request that would wait more than 200 ms for a worker, so the requests it does serve are ones whose clients are still waiting. The API keeps serving at about its capacity, 809 requests a second on average against 900 asked, and 10% fail instead of 71%. You chose which requests to give up, instead of letting the queue choose, and the next lesson is about doing that on purpose.
What happens if two instances fail?
Section titled “What happens if two instances fail?”The lab kills one, so test the margin with arithmetic. With four instances the service survives one loss, because 3 × 400 = 1,200 is above 900. After two losses it has 2 × 400 = 800, which is the same shortfall as the three-instance system after one. A spare covers one failure, and the next failure is a new decision. The same arithmetic shows why instances that fail together are worse than instances that fail alone: two instances in the same rack, or deployed together with the same bad build, behave like one failure that takes two.
Cascades also have an ingredient that the lab leaves out. The SRE book describes servers that run out of a resource under the extra load, such as memory, and crash, and so hand even more load to the servers that are left. In the lab the survivors queue and time out but they never die. A real cascade can be faster and wider than what you just watched.
- A cascading failure grows through positive feedback: a failure makes further failures more likely. The commonest loop is lost capacity, more work for the survivors, and then failures of the survivors.
- One API instance serves 400 requests a second, three serve 1,200, and two serve 800. At 900 requests a second the API goes from 75% to 113% of its capacity when one dies.
- In the lab a shortfall of 11% turns into 100% of requests failing, critical after 8.25 s, and 71% failing on average over the 30 seconds.
- A queue that holds requests longer than the client will wait turns an overload into wasted work.
- A spare instance (
3 × 400 = 1,200) and cheaper requests (about 1,067 for two instances) remove the overload and cost money or time. A deadline adds no capacity: it keeps the API serving, 10% fail instead of 71%, and it chooses what to refuse. - Spare capacity covers the failures it was sized for. Two losses from four is the same shortfall again.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.