Retry amplification and retry budgets
Retries at every layer multiply
Section titled “Retries at every layer multiply”A request rarely goes straight to the dependency that is failing. It goes through a chain: a client, a gateway, a service, a data-access layer, a database. If each layer retries the call it makes, the retries do not add up, they multiply. The attempts a layer makes are each a whole call for the layer below, and every one of those calls can be retried in turn.
Google’s SRE book gives the case. If the database is overloaded and the backend, the frontend and the JavaScript layer each issue 3 retries, which is 4 attempts, a single user action may create 64 attempts, 4³, on the database. A system that was built with a harmless-looking “retry 3 times” in each library has, together, a retry policy of 64.
Amazon’s article draws the opposite conclusion: its practice is to retry at a single point in the stack. A layer that does not retry passes the failure up, and the layer above, which knows more about what the user is waiting for, decides.
Mental model. Attempts per layer, raised to the power of the number of layers. Four attempts in three layers is 64. Two attempts in six layers is also 64.
Try it: three layers
Section titled “Try it: three layers”The lab has three layers, each making up to four attempts for every call, so up to three retries, with no wait between them. The dependency is down from 5 s to 13 s, and the lab opens at 10 s.
Three layers each retry the call below them three times. One request can become 4 × 4 × 4 = 64 attempts at the dependency, many times the traffic the users sent.
While the dependency is down, every attempt fails.
Share of attempts that fail on their own, even when the dependency is up.
Attempts the dependency can serve in any one second. It turns the rest away.
An error comes back after 0.1 s. With no answer, the caller waits the whole timeout before it can retry.
Each layer calls the next one and retries that call. The last layer calls the dependency.
How long a caller waits for an answer from the dependency.
The wait before a retry. None retries at once, fixed waits 0.5 s every time, and exponential starts at 0.5 s and doubles each time, up to 4 s.
Jitter makes each wait random. Full picks anywhere from zero to the delay, equal picks from half the delay to the delay. With no backoff there is no wait to randomise.
Each layer may retry only a share of the calls it makes, after a reserve of ten retries.
Closed, calls go through. After enough failures in a row it opens and calls fail at once. After a pause it is half-open and lets one probe through.
The lab runs in real time. Step moves on by one tenth of a second, Skip by five seconds.
What is happening
The dependency is down from 5 s to 13 s. Every attempt made now fails.
3 layers each make up to 4 attempts, so one user request can become up to 4 × 4 × 4 = 64 attempts at the dependency.
In the last second, user requests: 30; attempts at the dependency: 690; served: 0. The dependency can serve 60 a second.
With no backoff, a failed attempt is retried at once.
- User requests
- 300150 succeeded, 0 gave up, 150 still trying
- Attempts at the dependency
- 2,1007 for each user request, the most for one: 25
- At most for one request
- 64attempts at the dependency: 4 × 4 × 4
- Attempts, last second
- 690served: 0, capacity: 60, busiest tenth of a second: 75
- Circuit breaker
- Offswitched off
- Retries refused
- 0no retry budget
- Attempts (line)
- Served (filled)
- Outage (hatched)
| Seconds | New requests | Attempts | Served | Busiest tenth of a second | Dependency |
|---|---|---|---|---|---|
| 9 to 10 | 30 | 690 | 0 | 75 | Down |
| 8 to 9 | 30 | 540 | 0 | 60 | Down |
| 7 to 8 | 30 | 390 | 0 | 45 | Down |
| 6 to 7 | 30 | 240 | 0 | 30 | Down |
| 5 to 6 | 30 | 90 | 0 | 15 | Down |
| 4 to 5 | 30 | 30 | 30 | 3 | Up |
| 3 to 4 | 30 | 30 | 30 | 3 | Up |
| 2 to 3 | 30 | 30 | 30 | 3 | Up |
| Call | Attempts so far | For each user request | At most for one request |
|---|---|---|---|
| Layer 1 to layer 2 | 354 | 1.2 | 4 |
| Layer 2 to layer 3 | 696 | 2.3 | 16 |
| Layer 3 to the dependency | 2,100 | 7 | 64 |
Circuit breaker log
The circuit breaker is switched off.
At 10 s, user requests so far: 300 (150 succeeded, 0 gave up, 150 still trying). Attempts at the dependency: 2,100, 7 for each request. Circuit breaker: Off.
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- The lab advances in steps of 0.1 s. An attempt that succeeds, or that is answered with an error, takes one step, and a retry is sent on the step after the failure at the earliest, so no backoff means 0.1 s. A seeded random draw decides each failure rate and each jitter, so the same settings give the same run.
- Each layer calls the next one and retries that call. The layers above wait for the answer of the layer below, and only the attempt at the dependency has a timeout. Real services usually have a timeout at every layer, which leaves work running below after a caller has given up and can make the amplification worse than shown.
- The dependency fails in three ways: an outage window, a failure rate, and a capacity (it serves a fixed number of attempts in any one second and turns the rest away). A failure is either an error at once or silence until the timeout; real failures are a mix of both. A turned-away attempt costs the dependency nothing.
Simplifications
- A retry budget gives each layer a bucket that fills with a share of the calls it makes and loses one for each retry, starting with ten retries in reserve. One circuit breaker guards the calls to the dependency: it opens after a number of failures in a row, lets one probe through after a pause, and closes when the probe succeeds. Real libraries differ in how they count failures and how many probes they allow.
- No real client library and no connection-level effect is modelled: no connection set-up, no connection pool, no queueing in the network, no load balancer choosing another instance. The numbers illustrate the mechanism; they are not measurements of a product.
Parameter values are illustrative. They are not benchmarks of any real product.
The status line says that 3 layers each make up to 4 attempts, so one user request can become up to 4 × 4 × 4 = 64 attempts at the dependency, and At most for one request says 64. Nothing in the run reaches it. Look at what does happen: Attempts at the dependency is 2,100 for 300 user requests, which is 7 for each request, and at most 25 for one request. Attempts, last second is 690, while the users sent 30 requests in that second: 690 / 30 is 23 times as many.
The table of attempts at each layer shows where the load builds up. Layer 1 to layer 2 made 354 attempts, layer 2 to layer 3 made 696, and layer 3 to the dependency made 2,100. Each layer’s retries are added to those of the layers above it, and the dependency, at the bottom, receives the product.
Press Skip 5 s, to 15 s. The dependency has been back for two seconds, and it can serve 60 attempts a second, which is all it does. Attempts, last second is 900, so it serves 60 of the 900 it receives. Users sent 30 requests a second. The retries that piled up during the outage are still arriving, and Attempts at the dependency has reached 7,020.
A retry budget
Section titled “A retry budget”The way to stop the multiplication is to give the caller a limit on retries as a whole, not on one request. A retry budget does that. The SRE book suggests a retry budget for a server as a whole: for example, only allow 60 retries per minute in a process, and when the budget is used up, do not retry and fail the request. Amazon’s article describes a similar idea for its SDK, a token bucket that limits retries locally. A retry costs a token, calls add tokens, and when the bucket is empty the retry is not made.
The lab’s budget is that bucket for each layer. Every call adds a share of a retry to the bucket, set by Retries allowed, here 10% of calls. A retry costs a whole retry. The bucket starts with a reserve of ten retries, so that a quiet system can still retry a blip, and it holds at most twenty. A layer whose bucket is empty does not retry: the failure goes up.
The same three layers, but each may retry only a share of the calls it makes. The extra load stays small, and what cannot be retried fails quickly.
Steady spreads the requests evenly. In bursts, a second of requests arrives all at once, as when many clients act on the same schedule.
While the dependency is down, every attempt fails.
Share of attempts that fail on their own, even when the dependency is up.
Attempts the dependency can serve in any one second. It turns the rest away.
An error comes back after 0.1 s. With no answer, the caller waits the whole timeout before it can retry.
Each layer calls the next one and retries that call. The last layer calls the dependency.
How long a caller waits for an answer from the dependency.
The wait before a retry. None retries at once, fixed waits 0.5 s every time, and exponential starts at 0.5 s and doubles each time, up to 4 s.
Jitter makes each wait random. Full picks anywhere from zero to the delay, equal picks from half the delay to the delay. With no backoff there is no wait to randomise.
Each layer may retry only a share of the calls it makes, after a reserve of ten retries.
Closed, calls go through. After enough failures in a row it opens and calls fail at once. After a pause it is half-open and lets one probe through.
The lab runs in real time. Step moves on by one tenth of a second, Skip by five seconds.
What is happening
The dependency is down from 5 s to 13 s. Every attempt made now fails.
3 layers each make up to 4 attempts, so one user request can become up to 4 × 4 × 4 = 64 attempts at the dependency.
In the last second, user requests: 30; attempts at the dependency: 40; served: 0. The dependency can serve 60 a second.
With no backoff, a failed attempt is retried at once.
The retry budget lets a layer retry for 10% of the calls it makes. Retries refused so far: 529.
- User requests
- 300150 succeeded, 145 gave up, 5 still trying
- Attempts at the dependency
- 4081.4 for each user request, the most for one: 10
- At most for one request
- 64attempts at the dependency: 4 × 4 × 4
- Attempts, last second
- 40served: 0, capacity: 60, busiest tenth of a second: 5
- Circuit breaker
- Offswitched off
- Retries refused
- 529by a budget of 10% of calls
- Attempts (line)
- Served (filled)
- Outage (hatched)
| Seconds | New requests | Attempts | Served | Busiest tenth of a second | Dependency |
|---|---|---|---|---|---|
| 9 to 10 | 30 | 40 | 0 | 5 | Down |
| 8 to 9 | 30 | 40 | 0 | 5 | Down |
| 7 to 8 | 30 | 39 | 0 | 6 | Down |
| 6 to 7 | 30 | 49 | 0 | 12 | Down |
| 5 to 6 | 30 | 90 | 0 | 15 | Down |
| 4 to 5 | 30 | 30 | 30 | 3 | Up |
| 3 to 4 | 30 | 30 | 30 | 3 | Up |
| 2 to 3 | 30 | 30 | 30 | 3 | Up |
| Call | Attempts so far | For each user request | At most for one request |
|---|---|---|---|
| Layer 1 to layer 2 | 332 | 1.1 | 4 |
| Layer 2 to layer 3 | 368 | 1.2 | 16 |
| Layer 3 to the dependency | 408 | 1.4 | 64 |
Circuit breaker log
The circuit breaker is switched off.
At 10 s, user requests so far: 300 (150 succeeded, 145 gave up, 5 still trying). Attempts at the dependency: 408, 1.4 for each request. Circuit breaker: Off.
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- The lab advances in steps of 0.1 s. An attempt that succeeds, or that is answered with an error, takes one step, and a retry is sent on the step after the failure at the earliest, so no backoff means 0.1 s. A seeded random draw decides each failure rate and each jitter, so the same settings give the same run.
- Each layer calls the next one and retries that call. The layers above wait for the answer of the layer below, and only the attempt at the dependency has a timeout. Real services usually have a timeout at every layer, which leaves work running below after a caller has given up and can make the amplification worse than shown.
- The dependency fails in three ways: an outage window, a failure rate, and a capacity (it serves a fixed number of attempts in any one second and turns the rest away). A failure is either an error at once or silence until the timeout; real failures are a mix of both. A turned-away attempt costs the dependency nothing.
Simplifications
- A retry budget gives each layer a bucket that fills with a share of the calls it makes and loses one for each retry, starting with ten retries in reserve. One circuit breaker guards the calls to the dependency: it opens after a number of failures in a row, lets one probe through after a pause, and closes when the probe succeeds. Real libraries differ in how they count failures and how many probes they allow.
- No real client library and no connection-level effect is modelled: no connection set-up, no connection pool, no queueing in the network, no load balancer choosing another instance. The numbers illustrate the mechanism; they are not measurements of a product.
Parameter values are illustrative. They are not benchmarks of any real product.
Same layers, same outage, same 10 s. Attempts at the dependency is 408, 1.4 for each user request and at most 10 for one, where it was 2,100 without a budget, five times as many. Retries refused is 529. Attempts, last second is 40, against 690. The attempts at each layer are 332, 368 and 408: the layers still retry, a little, but the load no longer multiplies on the way down.
The budget has a price, and the lab shows it. At 10 s, User requests says 150 succeeded, 145 gave up and 5 are still trying. Without the budget it said 150 succeeded, none had given up and 150 were still trying. What cannot be retried fails fast.
What the budget costs
Section titled “What the budget costs”Press Skip 5 s twice, to 20 s, in this lab and in the previous one. With the budget, 358 requests have succeeded, 239 gave up, and the dependency has received 739 attempts. Without it, 570 requests have succeeded, none gave up, and the dependency has received 9,270 attempts. So the budget saved 9,270 − 739, which is 8,531 attempts, and the price was 570 − 358, which is 212 requests that did not get an answer. Whether that is a good trade depends on what the dependency can take.
In the lab the dependency comes back at 13 s whatever load it receives, so the retries cost only attempts. An overloaded dependency is different. The SRE chapter is about how an overload spreads from one component to the next, and a retry budget is one of the measures it lists. It is a protection for the dependency first, and for the callers’ own threads and connections second. The cost lands on the users whose requests give up early, and they get a quick failure instead of a slow one.
The C# example of the previous lesson has a budget of 6 retries in all. After the dependency stays down for good, its last line reads retry budget left: 0, and the next call gets one attempt and gave up: 503 service unavailable (retry budget empty) after 1 call(s).
Check the arithmetic and what a caller does with an empty budget.
Check your understanding: retries that multiply
This quiz needs JavaScript to check your answers.
A user request goes through four layers: a gateway, an orders service, a stock service and a data-access layer. Each layer makes up to 3 attempts for every call it makes (the first one and 2 retries) and retries a failed call at once. The database at the bottom is down.
At most how many attempts can one user request cause at the database?
Enter a number and choose its unit.
A service makes 2,000 calls to a dependency in one minute. Its retry budget allows one retry for every 10 calls, and its reserve is already used up. The dependency is down, so every call fails.
At most how many retries can the service make in that minute?
Enter a number and choose its unit.
The same service has used all of its retry budget, and another call fails.
What should the caller do with the failed call?
Choose one answer.
What happens if the budget is empty when a brief blip arrives?
Section titled “What happens if the budget is empty when a brief blip arrives?”A budget that has been spent during an outage refills only as calls are made. At 30 calls a second and a share of 10%, 30 × 10% is 3 retries a second per layer. If a short blip follows the outage, a layer can retry 3 of its failed calls a second, and the rest fail at once. That is deliberate. The budget cannot tell a blip from the start of the next outage, and it chooses to protect the dependency. A larger share would let more blips through and would also allow a larger storm. There is no value that is right for both: the share is a decision about how much extra load the dependency can take.
- Retries at every layer multiply: attempts per layer to the power of the number of layers. Three layers of four attempts make up to 4 × 4 × 4 = 64.
- In the lab, 300 user requests became 2,100 attempts at the dependency at 10 s, and 690 of them arrived in the last second, 23 times the users’ 30.
- A retry budget limits the retries as a whole. With one, the same run made 408 attempts and refused 529 retries.
- The budget is a trade: by 20 s it had saved 8,531 attempts and left 212 requests without an answer.
- When the budget is empty the caller does not retry. It fails the request, or serves a fallback, at once.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.