Retry Storms & Retry Budgets
Jittered backoff spreads retries out in time, but it doesn't reduce how many there are. When a service is overloaded rather than briefly unavailable, retries add load exactly when there is none to spare. Two mechanisms make this dangerous: amplification through layers, and metastable failure, where retries keep a service down after the original trigger is gone.
Amplification through layers
If every layer of a call chain retries, the attempts multiply. With 3 attempts at each of 3 layers, one user click can become 27 calls to the database when it is failing:
def attempts_at_bottom(layers, attempts_per_layer):
return attempts_per_layer ** layers
print("layers attempts/layer calls reaching the failing bottom layer")
for layers in (1, 2, 3, 4):
for attempts in (2, 3):
print(f"{layers:>6} {attempts:>15} {attempts_at_bottom(layers, attempts):>10}")layers attempts/layer calls reaching the failing bottom layer
1 2 2
1 3 3
2 2 4
2 3 9
3 2 8
3 3 27
4 2 16
4 3 81
The fix is organisational as much as technical: retry at one layer only, usually the one closest to the user (or the one that knows the operation is idempotent), and make the other layers fail fast. Service meshes make this easy to get wrong, because a mesh retry policy adds a layer that application code doesn't see.
Metastable failure
A system is metastable when it has a stable good state and a stable bad state, and a temporary trigger can push it from one to the other. Retries are the classic sustaining effect: an overloaded server answers slowly, clients time out and retry, the retries add load, the server stays overloaded, and so on, long after the trigger is over.
The model has a server with capacity 100 requests per tick and 80 new requests per tick (80% utilisation, a comfortable margin). For two seconds (ticks 50–69) a bad node halves its capacity. While overloaded, the server keeps working, but the more overloaded it is, the more of its answers arrive after the client already gave up, so less useful work gets done. Four client behaviours:
- no retries;
- 4 attempts, with jittered backoff of 1–4 ticks;
- the same, with a retry budget: retries may add at most 10% to the new-request rate (a token bucket);
- adaptive throttling from the SRE book: each client tracks requests and accepts over the last 20 ticks and
rejects new requests locally with probability
max(0, (requests − 2 × accepts) / (requests + 1)).
import random
NEW, TICKS, MAX_ATTEMPTS = 80, 300, 4
TRIGGER = range(50, 70) # capacity drops to 40 for 2 seconds (a bad node, a GC storm)
def capacity(t):
return 40 if t in TRIGGER else 100
def run(mode, seed=3):
rng = random.Random(seed)
pending, tokens, window = {}, 0.0, []
stats = []
for t in range(TICKS):
arrivals = [1] * NEW + pending.pop(t, [])
if mode == "adaptive throttling": # client-side: reject locally with probability p
req = sum(r for r, _ in window[-20:])
acc = sum(a for _, a in window[-20:])
p = max(0.0, (req - 2 * acc) / (req + 1))
arrivals = [a for a in arrivals if rng.random() >= p]
load, cap = len(arrivals), capacity(t)
# overloaded: the server stays busy, but more and more requests finish after the client's timeout
useful = load if load <= cap else int(cap * max(0.0, 1.5 - 0.5 * load / cap))
window.append((load, useful))
if mode == "retry budget 10%":
tokens = min(tokens + 0.1 * NEW, 50.0)
rng.shuffle(arrivals)
for attempt in arrivals[useful:]:
if mode == "no retries" or attempt >= MAX_ATTEMPTS:
continue
if mode == "retry budget 10%":
if tokens < 1:
continue # budget exhausted: fail fast instead of retrying
tokens -= 1
pending.setdefault(t + rng.randint(1, 4), []).append(attempt + 1)
stats.append((load, useful))
return stats
print(f"{'mode':<22}{'before':>14}{'trigger':>14}{'+1 s':>14}{'+10 s':>14}{'+23 s':>14}")
for mode in ("no retries", "4 attempts", "retry budget 10%", "adaptive throttling"):
s = run(mode)
cells = []
for t in (40, 60, 80, 170, 299):
load, ok = s[t]
cells.append(f"{load:>4} {ok / load:>5.0%} ok")
print(f"{mode:<22}" + "".join(f"{c:>14}" for c in cells))mode before trigger +1 s +10 s +23 s
no retries 80 100% ok 80 25% ok 80 100% ok 80 100% ok 80 100% ok
4 attempts 80 100% ok 292 0% ok 335 0% ok 337 0% ok 300 0% ok
retry budget 10% 80 100% ok 90 17% ok 80 100% ok 80 100% ok 80 100% ok
adaptive throttling 80 100% ok 195 0% ok 60 100% ok 80 100% ok 80 100% ok
The trigger lasts two seconds for every behaviour. Without retries, the service is back as soon as the capacity returns. With plain retries it never recovers: the retries alone keep the load above capacity, and the success rate stays at zero for as long as the simulation runs, although nothing is broken any more. That is the shape of many real large outages: the trigger (a deploy, a failover) is short; the retry storm makes it long. The usual way out is drastic: shed load at the edge, block traffic, or restart clients.
Both safeguards break the loop. The retry budget caps how much extra load retries can add; adaptive throttling lets clients notice that most requests are failing and stop sending most of them, so the server gets breathing room and recovers.
Retry budgets in practice
| Where | Mechanism |
|---|---|
| gRPC | retry policy with maxAttempts, plus retry throttling (maxTokens, tokenRatio) in the service config |
| Envoy / Istio | retry_budget in a cluster's circuit-breaker thresholds (budget_percent, min_retry_concurrency); attempts per route with Envoy's retry_policy.num_retries or Istio's retries.attempts |
| application libraries | a token bucket shared by all calls to one dependency, refilled by successful requests |
The rule of thumb behind most of them: retries should be at most about 10% of requests. Under normal conditions that's plenty for transient errors; during an overload it caps the amplification at 1.1x.
Other safeguards in the same family
- Circuit breakers stop calling a dependency that keeps failing (next lesson).
- Load shedding on the server rejects work it can't finish in time, cheaply and early (Load Shedding).
- Deadlines stop work for callers that already gave up (Timeouts & Deadlines).
- Jitter on everything periodic (cron jobs, cache expiry, client polling), not only on retries: synchronised clients cause storms too.
Test yourself
Three layers each try a call up to 4 times. How many calls can reach a failing database for one user request?
- 12
- 16
- 64
- 4
In the model, why did the service stay down after the capacity came back?
- The bad node was still broken
- Retries kept the load above capacity, so requests kept timing out and being retried: a metastable failure
- The model has a bug
- Clients stopped sending requests
What does a 10% retry budget guarantee during an overload?
- That every request succeeds
- That retries add at most about 10% to the load, so they can't multiply it
- That the service never overloads
- That retries happen faster