Skip to content

Retry with Backoff

Medium — good to knowBackend

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.