Retry with Backoff
ELI5 — The Vibe Check
Retry with backoff means trying again when something fails, but waiting longer between each attempt. First retry: wait 1 second. Second: 2 seconds. Third: 4 seconds. This gives the failing service time to recover instead of hammering it with immediate retries.
Real Talk
Retry with backoff is a resilience pattern that retries failed operations with progressively increasing delays between attempts. It prevents overwhelming a recovering service with immediate retries. Combined with maximum retry counts and jitter (randomized delay) to avoid thundering herd problems. Used for transient failures like network timeouts and rate limit responses.
Show Me The Code
async function retryWithBackoff(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (err) {
if (i === maxRetries - 1) throw err;
const delay = Math.pow(2, i) * 1000 + Math.random() * 1000;
await new Promise(r => setTimeout(r, delay));
}
}
}
When You'll Hear This
"Retry with exponential backoff so we don't DDoS our own payment provider." / "Add jitter to the backoff so all retry clients don't hit the server at the same time."
Related Terms
Circuit Breaker
Circuit Breaker is like the electrical circuit breaker in your house.
Exponential Backoff
Exponential backoff doubles the wait time between each retry. Wait 1s, then 2s, then 4s, then 8s.
Jitter
Jitter adds randomness to retry delays so all your clients don't retry at the exact same time.