← Math
Math

Retry amplification and backoff

Why did the database stay down after it recovered?

Count the work retries can cause, then check how their waits and attempt durations fit a deadline.

Outcome

Count the attempts one request can cause, compare healthy load with the outage bound against capacity, and fit a capped backoff to the caller’s deadline.

Terminology (6)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Retry amplification
One request turning into many downstream attempts because several layers each retry.
Retry storm
A failing service receiving more load because its callers retry, which keeps it failing.
Exponential backoff
Waiting longer before each retry, usually multiplying the wait by a fixed factor.
Backoff cap
The longest single wait, so delays stop growing after a few retries.
Jitter
Randomness added to waits so many clients do not retry at the same moment.
Deadline
The time by which the caller needs an answer; attempts that cannot finish before it are wasted.

Why this matters

Retries hide brief failures, so many clients and service frameworks offer them. Stacked across layers they multiply, and during an outage they turn into a flood aimed at the one service that is already struggling. The arithmetic is short, and it decides where retries belong, how many are safe and how long the caller will wait.

This lesson assumes expected values and geometric sums from earlier lessons.

Attempts, retries and waiting

A retry is another attempt after a failure, so an allowance of r retries permits r + 1 attempts. With nested retry loops, each outer attempt can restart the inner loop. Expected work depends on the failure model; the all-failures case gives a separate bound on work per original request.

Backoff inserts waits between attempts. A cap limits each wait, and jitter varies it to spread clients out in time. The caller’s deadline covers both those waits and the attempts themselves, so a configured attempt may never finish soon enough to help.

01Retries multiply across layers

Retries multiply across layers

The orders database stalled for a minute. When it came back it faced four times its normal load, because every layer above it had been retrying, and it fell over again. Each team had chosen a sensible number of retries; nobody had multiplied them.

Predict the three lines this program prints.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const layerRetries = [2, 3, 2]; // app, gateway, orders service

console.log(layerRetries.reduce((product, r) => product * (r + 1), 1)); // worst case per tap
const [rate, p, retries] = [500, 0.02, 3];
let expected = 0;

for (let k = 0; k <= retries; k++) expected += p ** k;

console.log((rate * expected).toFixed(2)); // database attempts per second, healthy
console.log((rate * (retries + 1)).toFixed(2)); // during an outage
Why is the first line 36 and not 10?

02Expected versus the outage bound

Expected versus the outage bound

Database attempts per second at 500 requests per second, 3 retries
StateAttempts per requestAttempts per second
Healthy, 2% of attempts fail1.0204510.20
Down, every attempt fails42,000

The team first centralizes retries in one layer, allowing three retries. Expected attempts are 1+p+p²+p³ because reaching attempt k+1 requires k consecutive failures under the constant independent failure model. At p=.02 this is 1.020408; at p=1 it is 4. Multiplying by 500 original requests/s gives the table’s long-run offered work. With capacity 1,200, the outage workload exceeds the model capacity and can impede recovery. The factor 4 bounds work per original request, not the instantaneous retry arrival rate: old queued retries can bunch together, and backoff changes when they arrive.

03Capped backoff

Capped backoff

Waiting longer before each retry spreads the load: 100 ms, 200, 400, 800, and then capped at 800 ms so the waits stop growing. Adding jitter, a random wait up to that length, reduces synchronized retry bursts. Full jitter samples uniformly from 0 to each capped wait, so its mean wait is half the cap; the deterministic schedule below uses the full waits, not jittered averages.

fetch has no retries of its own; AbortSignal.timeout(ms) bounds a single attempt so the schedule’s attempt time holds.

04Count against the deadline

Count against the deadline

All attempts fail after 300 ms; full deterministic waits, deadline 3 seconds
AttemptStartsEnds
10300
2400700
39001,200
41,6001,900
52,7003,000
63,8004,100
With 6 retries configured, how many attempts can actually help this caller?

05Retry in one place

Retry in one place

06Tame the retry storm

Tame the retry storm

The orders team first counts the full retry tree. After assigning retries to one owner, it compares healthy expected work and maximum work per request with capacity. The schedule request then checks whether those configured attempts can finish for this caller; adding waits without attempt durations can still count work that cannot help.

A layered retry path

Worst-case attempts, load during an outage, then retries before the deadline.

  1. easy · M-RETRY-V4-1 Worst-case attempts
  2. medium · M-RETRY-V4-2 Load during an outage
  3. hard · M-RETRY-V4-3 Retries before the deadline
In the frontend Deadline-aware retries in Next.js and Svelte Optional

Browser code is often the top layer. Capped backoff with full jitter, a timeout on each attempt, and a maximum retry count and a deadline check before every attempt bound this read request’s work. The example retries network failures and 5xx responses for a GET, not an order-creation write. It rechecks after sleeping because browser timers can resume late; suspension and scheduling mean it is not a hard real-time guarantee.

Estimate.tsx
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
// GET-only retry policy: network errors and5xx; timers are not hard real-time deadlines.
export async function fetchWithin(
  url: string,
  deadlineMs: number,
  attemptMs: number,
  retries = 6
): Promise<Response> {
  const expires = performance.now() + deadlineMs;

  for (let k = 0; k <= retries; k++) {
    if (performance.now() + attemptMs > expires)
      throw new Error("No complete attempt fits the deadline");

    const response = await fetch(url, { signal: AbortSignal.timeout(attemptMs) }).catch(
      () => null
    );

    if (performance.now() > expires) throw new Error("Deadline passed");
    if (response && response.status < 500) return response;
    if (k === retries) break;

    const wait = Math.random() * Math.min(100 * 2 ** k, 800);

    if (performance.now() + wait + attemptMs > expires) break;

    await new Promise((resolve) => setTimeout(resolve, wait));
    // The next loop rechecks the budget if the timer resumed late.
  }

  throw new Error("Retry budget exhausted");
}

Check this idea later
Only the app retries, 2 times; inner layers do not. How many database attempts can one tap cause?
Why does jitter help during recovery?
Sources

Values above were computed in Node 22 and run in Go 1.27, Rust 1.99 and Apple clang 17. The retry path is a worked model.

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.