Exponential backoff calculator

Pick a base delay, multiplier, cap and jitter strategy, and see every retry's wait, how long the whole thing can take, and the code to do it.
Jitter
Shortest total wait
7.75 s
Typical total wait
11.63 s
Longest total wait
15.50 s
RetryWaitRangeElapsed (typical)
1250 ms to 500 ms375 ms
2500 ms to 1.00 s1.13 s
31.00 s to 2.00 s2.63 s
42.00 s to 4.00 s5.63 s
54.00 s to 8.00 s11.63 s

Waits only. Add each attempt's own duration (up to its timeout) to get the real time to give up.

const BASE_MS = 500;
const FACTOR = 2;
const CAP_MS = 30000;
const MAX_RETRIES = 5;

/** Wait before retry number `n` (1-based). Equal jitter. */
function backoffMs(n: number): number {
  const exp = Math.min(CAP_MS, BASE_MS * FACTOR ** (n - 1));
  return exp / 2 + Math.random() * (exp / 2);
}

// A Retry-After from the server wins over your own backoff:
// const wait = retryAfterMs ?? backoffMs(n);

How exponential backoff works

After each failed attempt, the client waits before trying again, and each wait is longer than the last: the base delay times the multiplier to the power of the retry number, up to a cap. With a 500 ms base and a multiplier of 2, that's 500 ms, 1 s, 2 s, 4 s and so on. The growing gaps give an overloaded or rate-limited server room to recover instead of being hit again straight away.

Why add jitter

If many clients fail at the same moment (a deploy, a brief outage), plain exponential backoff makes them all retry at the same moments too, in synchronized waves. Jitter randomizes each wait so the retries spread out. AWS's write-up Exponential Backoff and Jitter compares the strategies in this calculator:

  • Full jitter picks a random wait between 0 and the exponential value. It spreads load the most, but a wait can land very close to 0.
  • Equal jitter keeps half the exponential value and randomizes the other half, so a retry never goes out sooner than half the planned wait.
  • Decorrelated jitter picks a random wait between the base delay and three times the previous wait, capped.

Retry-After beats your own backoff

When a 429 or 503 response carries a Retry-After header, the server is telling you when to come back. Use that instead of your computed delay, and if it's longer than you're willing to wait, give up and report the error. Paste a value into the Retry-After parser to see how a client should read it, and check which status codes to retry at all.

Test the schedule, not just the formula

A unit test of the delay function won't catch a client that ignores Retry-After, retries a 422, or never gives up. Point your client at a Jitterbox endpoint that fails on purpose, and its resilience report checks the real timing of every retry. The guide How to test retry logic walks through it.

Test it against real failures

Jitterbox gives you a fake version of the APIs you call, at a real URL, and makes them fail on purpose. Free during the beta.