Backend & Node.js · APIs, data and failure
How do retries and backoff work without making an outage worse?
Short answer
Retry only transient failures, use exponential backoff with jitter, cap attempts and total time, and respect Retry-After. Retries must be idempotent and limited by a budget, otherwise they amplify load during an outage.
A retry helps when a failure is temporary: a connection reset, a timeout or a 503. It hurts when the failure is permanent or when every client retries at once. The goal is to recover from transient faults without creating a retry storm.
async function withRetry(fn, attempts = 4) {
for (let attempt = 0; attempt < attempts; attempt += 1) {
try {
return await fn();
} catch (error) {
if (!isRetryable(error) || attempt === attempts - 1) throw error;
const base = 100 * 2 ** attempt;
const delay = base + Math.random() * base;
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
}Rules
- Retry timeouts, connection resets, 429 and 502 or 503, not 400 or 422
- Use exponential backoff with full or decorrelated jitter
- Respect Retry-After when the server provides it
- Cap total attempts and total elapsed time
- Make the operation idempotent or pass an idempotency key
- Limit retries as a fraction of traffic so an outage does not triple load
Retries stack across layers. A client retries the gateway, the gateway retries the service, and the service retries the database, multiplying the original request. Decide where retries belong, usually one layer close to the failing dependency, and make the others fail fast.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Which errors should not be retried?
- 2Why is jitter important?
- 3How do retries interact across service layers?
- 4When should you respect Retry-After?
Say it in the interview
I retry only transient failures and use exponential backoff with jitter, a bounded attempt count and a total time limit. The operation must be idempotent or carry an idempotency key, and I respect Retry-After from the server. I also decide which layer owns retries, because retries at every layer multiply load during an outage. A retry is a resilience tool, not a default for every error.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Backend & Node.js mock interview and get scored feedback on depth, clarity and confidence.