Skip to the page

Background work, webhooks and real-time · senior

Retries, backoff and idempotent consumers

Retry only failures that may succeed later (timeouts, 5xx, 429), wait longer each time with exponential backoff plus random jitter, cap the attempts, and make the receiving side idempotent because retries and at-least-once delivery create duplicates.

The notes

What you must know

  • Retry: network errors, timeouts, 502/503/504, 429 (respect Retry-After). Do not retry: 400, 401, 403, 404, 422 (the request itself is wrong).
  • Exponential backoff with full jitter: delay = random(0, min(cap, base x 2^attempt)). Jitter spreads retries so clients do not hit the server in sync (retry storms).
  • Cap attempts and total time; put a timeout on every outgoing call (fetch with AbortSignal.timeout(ms)).
  • Retries multiply load during outages: 3 layers each retrying 3 times = 27 calls. Retry at one layer; use a circuit breaker to stop calling a dependency that keeps failing.
  • Idempotent consumers: store processed message/event ids (unique constraint) and skip duplicates; or make the operation naturally idempotent (SET status = 'paid' rather than balance = balance + x).
  • Outbox pattern: write the business change and an 'event to publish' row in the same DB transaction; a relay publishes it. This avoids 'saved to DB but message lost' and vice versa.

The red pen

Common traps: mistake → fix

  • Mistake: Retry every error immediately

    Fix: instant retries of 4xx never succeed and synchronized retries can take a struggling service down.

  • Mistake: Retries are safe for any request

    Fix: retrying a non-idempotent POST without an idempotency key can duplicate the action.

Easy to hard

Questions interviewers ask, easy to hard

  1. Which errors should a client retry?
  2. What is exponential backoff and why add jitter?
  3. What is a retry storm? A circuit breaker?
  4. How do you make a message consumer safe when messages can arrive twice?
  5. What problem does the outbox pattern solve?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview