Key takeaways
- ✓With no limit on waiting, a service at exactly its capacity of 800 requests a second answered 39% of requests in time, and from 1.5 times that load on, almost none: it kept working on answers for clients that had already given up, and after the 3× step it needed 37 seconds to clear the backlog.
- ✓Load shedding with a queue of at most 8 waiting requests per instance kept goodput (requests answered in time) flat at 756 to 777 a second from the capacity up to three times it, with a p99 (the slowest one in a hundred) of 65 ms for the requests it let in, and refused the rest at once with a 503, the HTTP status for 'busy, try later'.
- ✓Dropping requests whose client had already left barely helped, with 400 a second answered at 1× and 25 at 1.5×, because a first-come, first-served queue hands a worker the request that has waited longest, just before its deadline; a 200 ms limit on waiting did what the queue bound did, with answers in about 220 ms.
- ✓Priorities decide whom to refuse: with 1,600 requests a second, half marked critical, priority shedding answered 95% of the critical ones and 0.1% of the sheddable ones, while with no limit both groups got nothing.
- ✓Retrying at once after a 10-second slowdown that ended at 25 seconds sent 3.34 attempts per request, about 2,300 attempts a second against 777 a second of real capacity, and goodput stayed at zero to the end of the 70-second run: a metastable failure, kept down by its own retries after the cause was gone.
- ✓Backoff with jitter, waits of up to 50, 100 and 200 ms before the three retries, still averaged 3.34 attempts per request and never recovered (22% answered OK overall), because jitter spreads retries out in time without making fewer of them.
- ✓A retry budget that allows retries for at most 10% of recent requests cut the average to 1.06 attempts and recovered 27 seconds after the slowdown ended, while a server that allowed at most 8 waiting and dropped expired requests recovered at once against the same worst-case client, with 92% answered OK.
Lab 17 of the system design labs sent a service 560 requests a second, then slowed the service down for 10 seconds. When the slowdown ended, clients that retried at once got nothing back: no request succeeded in the 45 seconds that followed. Backoff with jitter didn't fix it. A retry budget did, slowly, and a server that refused work early recovered at once. This chapter takes the three failures apart: why a line makes overload worse, how retries multiply the load, and why saying no early is the fix that works whatever the clients do.
The examples come from Lab 17 (Overload, Rate Limits and Backpressure), the scripts 02_shedding.py (the load sweep) and 03_retry_storm.py (the slowdown and the retry policies). The policy code is in shedding.py (the server's queue and limits) and retry.py (the client's retry rules). The service has four instances, each with four workers, and each request holds a worker for 20 ms. So one worker does 50 requests a second, and the four instances together 800. The lab ran on the same laptop as the earlier chapters, an Apple M4 Max with Docker Desktop, and each configuration is one recorded run.
Goodput, and why a line makes it fall
Throughput counts every request the server finishes. Goodput counts only the ones answered OK within the client's timeout. The difference is the whole story here: a server can be busy every second and deliver nothing a user can use.
A service with a fixed number of workers serves a fixed rate, here 800 a second. Past that rate, requests wait. With no limit on the waiting line, every request waits behind every earlier one. Once the wait is longer than the client's timeout (one second in the sweep), the client has gone, but the server still cooks the answer. The work is done for nobody.
Think of a restaurant with sixteen cooks, where diners who wait too long walk out. If the kitchen keeps cooking every order, including the ones whose diners have left, the cooks are busy and the paying diners still wait.
Retries multiply the load
A timeout makes the client send again. That is the whole mechanism, and it turns a slow answer into more load. Under overload, the retry arrives at a server that is already full, so it also waits, and it too may time out and be sent again.
With three retries allowed, one failed request can become four attempts. If most requests fail, the load can reach four times the normal rate, at exactly the moment the servers have no spare room. The trigger can end, and the load stays above capacity, because the failures it creates are what keep the load high. That is a metastable failure: the system is stuck in a bad state that its own load sustains, after the cause has gone.
The incident review in that case would blame the slowdown, which ended at 25 seconds. The outage did not end, so the cause is the loop: retries with no budget, against a queue with no bound. The next 10-second slowdown would do it again.
Jitter spreads retries out, and a budget makes fewer
Backoff with jitter waits a random time before each retry, up to a limit that doubles with each try. In the lab, the limit was 50 ms before the first retry, 100 ms before the second and 200 ms before the third. Jitter stops the clients from retrying in lockstep. It does not reduce how many retries there are, so a failing server still sees up to four attempts per request.
A retry budget limits retries as a share of the traffic. The lab's budget allowed retries for at most 10% of the requests in a 10-second window, plus a small floor, so in an outage the extra load is capped at about 10%. Once the budget is spent, the client gives up on that request rather than retrying it.
Load shedding: refuse work early
Load shedding means refusing work at the door, at once, when the server can't serve it in time. A refused request costs almost nothing. An accepted request that is answered too late costs a worker, and gives nothing back to the user.
The lab's server limits its line. With at most 8 requests waiting per instance, the next request gets an immediate 503 instead of joining the line. The line never grows, so the wait is bounded: at most 8 waiting over 4 workers, about 40 ms, which is the arithmetic of the setup. The requests it let in were served in time.
The other limits the lab tried were weaker. Dropping a request whose client has already gone sounds right, but a first-come, first-served queue hands a worker the request that has waited longest, which is the one just before its deadline. It gets cooked and answered a moment too late. A 200 ms limit on waiting works like the bound: the queue it allows is about 200 ms long, and goodput is the same.
Priorities decide whom to refuse. When half of the traffic is marked critical and half sheddable, shedding the sheddable half first keeps the critical half flowing.
Goodput per second is the share of requests answered within the client's 1 s timeout. Bars are scaled to the 800/s capacity; each row is one 20 s step, measured over its last 10 s.
Priorities, 1,600/s with half critical and half sheddable
With shedding, sheddable requests are refused once 4 wait and critical ones may queue up to 16. Critical p99 110 ms. Goodput 760/s.
The workflow and the results
The load sweep. 02_shedding.py raises the load in 20-second steps, from 0.5× to 3× the capacity of 800 a second, with a 1-second client timeout and no retries. Goodput is measured over the last 10 seconds of each step. It takes about 8 minutes.
| Offered per second | No limit: answered in time | Bounded queue (8): answered in time |
|---|---|---|
| 400 (0.5×) | 396 (100%) | 396 (100%) |
| 800 (1×) | 313 (39%) | 756 (94%) |
| 1,200 (1.5×) | 0 | 764 (63%) |
| 1,600 (2×) | 0 | 770 (48%) |
| 2,400 (3×) | 0 | 777 (33%) |
Without a limit, goodput collapsed at exactly the capacity. After the 3× step, the backlog took 37 seconds to drain. With the bound, the 3× step turned away 16,114 requests in its last 10 seconds, each with a fast 503, and the p99 of the requests it served was 65 ms.
The retry storm. 03_retry_storm.py sends 560 requests a second for 70 seconds, with a 0.5-second client timeout and up to 3 retries. From 15 to 25 seconds every request takes three times as long, so the capacity falls to about 267 a second. It takes about 10 minutes.
| Client retries | Server | Attempts per request | Goodput, last 15 s | Recovered after the slowdown | OK overall |
|---|---|---|---|---|---|
| None | No limit | 1.00 | 557/s | After 15 s | 65% |
| Retry at once | No limit | 3.34 | 0 | Never | 22% |
| Backoff with jitter | No limit | 3.34 | 0 | Never | 22% |
| Retry budget (10%) | No limit | 1.06 | 557/s | After 27 s | 49% |
| Retry at once | Bounded queue (8) and drop expired | 1.27 | 557/s | At once | 92% |
Every timeout is sent again at once, up to 3 times. Attempts pass 2,000 a second and goodput never returns.
goodput per second (answered in time)attempts per second (retries included)
Recovered: never (0 for the last 15 s). Load 560/s against about 267/s during the slowdown and about 777/s normally. One run per policy.
Read the table in this order. Retry at once and backoff with jitter both sent about 2,250 to 2,300 attempts a second in the last 15 seconds, from clients that wanted 560, and both stayed at zero goodput. The budget cut the attempts to 1.06 a request and recovered, but its allowance came in bursts (about 1,100 attempts in each of four seconds, 16, 26, 36 and 46), and it took 27 seconds to come back, against 15 with no retries at all. The server's own limit was the best of the five: with the worst client, retries were refused fast rather than queued, so the queue never filled and goodput was back the moment the slowdown ended.
Caveats
- One run per setting. Each policy and each sweep step is a single recording, so the percentages are not error bars. The lab does not repeat runs to show how much they vary.
- The "capacity" is a stand-in. Each request holds a worker for a 20 ms sleep, not a real piece of work, so the top speed is set by the harness. The recorded goodput plateau was 756 to 777 a second, below the 800 on paper, so the sweep's 1× step was already slightly over what the service could do.
- Waiting time is arithmetic. The "at most 40 ms" for 8 waiting over 4 workers is what the setup implies. The lab measured latency, not the queue length.
- Only one client type with one set of numbers. Every client had a 0.5-second timeout and 3 retries. The retry policies were not tested across two tiers of services, where retries multiply once per tier, and the budget's 10% and 10-second window are one choice among many.
- The priority test is one point. It was run at 1,600 a second, half critical, with one queue setting.
- Not covered: circuit breakers, graceful degradation, autoscaling and the flash sale, which the next episodes take up; adaptive concurrency limits; a last-in, first-out queue; the lab's rate limiters; and any real network, TLS or multi-region failure.
The checklist
- Measure goodput, not throughput. A server busy with answers nobody is waiting for is overloaded, whatever its CPU says.
- Bound the line. A short queue with a fast 503 keeps the wait short and the rest of the traffic on time.
- Count retries in the load. Every retry is more load at the moment of the failure. Multiply attempts by the number of tries before you size the system.
- Use jitter to spread retries, and a budget to limit them. Jitter alone kept 3.34 attempts per request; a budget brought it to 1.06.
- Let the server refuse work. It works whatever the clients do, and the worst client was the case where it mattered most.
- Mark what can wait. Refuse sheddable traffic first, so critical traffic keeps flowing.
Quiz
1.After a 10-second slowdown ends, clients that retry at once keep getting zero answers in time. Why does the outage outlast the slowdown?
2.Backoff with jitter and a retry budget both change when retries are sent. Which one reduced the number of attempts per request?
3.Dropping requests whose client has already gone, instead of answering them, barely helped at capacity: 400 a second answered at 1×. What explains it?
Check your understanding
Try each question before opening its answer.
Why did the 10-second slowdown's outage last well past its end, with retries at once?
The retries themselves kept the servers overloaded. Each request was sent up to four times, so about 2,300 attempts a second reached servers that could do about 777 a second. The queue filled with requests that would time out anyway, so goodput stayed at zero, even though the servers were healthy again. The trigger had gone, and the loop it started had not.
Backoff with jitter spreads retries out in time. Why didn't it keep the load down, when the retries were up to 200 ms apart?
Jitter changes when retries happen, not how many there are. With three retries allowed, a request that keeps failing still produces four attempts, and the lab averaged 3.34 attempts per request with or without it. The waits were a fraction of a second against a sustained overload, so the retries still landed on full servers.
A retry budget spends its allowance in bursts. Why does that make recovery slower than no retries at all?
The budget counts retries over a 10-second window, so it spends its allowance all at once and then waits for the next window. In the lab, that gave about 1,100 attempts a second in each of four bursts, 10 seconds apart, and each burst kept the servers full for a while. Recovery came 27 seconds after the slowdown ended, against 15 with no retries.
Dropping requests whose client had already left barely helped at capacity. Why not?
In a first-come, first-served queue, the request that reaches a worker is the one that has waited longest, so it reaches the worker just before its client gives up. Dropping expired requests therefore removed very little, and the ones that were served were answered about a second after they were sent, too late. A bound on the queue keeps the wait short, so what gets served is still on time.
Why does the server's own limit work even when the clients are the worst they can be?
The limit does not depend on what the clients do. A request that finds 8 already waiting is refused at once, so it costs the server almost nothing, and the queue stays short. Even with immediate retries sending about 2,300 attempts a second, goodput was back the moment the slowdown ended, and 92% of all requests were answered OK, against 22% without the limit.
Next up: Chapter 42, circuit breakers and degrading gracefully: a flash sale with 5× the normal traffic, which page parts to switch off under load, and a breaker in front of a slow dependency.