Retry with exponential backoff and jitter
Medium25 minFree, no account
Easy to write, easy to write in a way that makes an outage worse.
The question
Write retry(fn, { attempts, baseMs, maxMs, signal }) that retries a failing async function with exponential backoff.
Explain why jitter matters and which errors you should not retry.
await retry(() => fetch(url), {
attempts: 5, baseMs: 100, maxMs: 10_000, signal
});
// delays roughly: 100, 200, 400, 800, each randomised25:00Commit to an answer before you open the solution. Reading it first teaches you to recognise good answers, which is not the skill being tested.
Stuck?
0 of 3 hints takenThe worked solution
written by a person · not a gradeScore yourself
0 of 5 marked- Exponential backoff with a cap20
- Jitter, with the thundering-herd explanation25
- A retryable-error predicate rather than retrying everything25
- Raised idempotency20
- Cancellation that interrupts the wait10
We run no AI here and nothing on this page grades you. The score is yours, and the useful number is the one you get on the same problem a month from now, cold.
kept in this browser only