Retry Pattern
ELI5 — The Vibe Check
Retry Pattern is trying something again when it fails, because sometimes failures are temporary (network hiccup, brief overload). But it's not just blindly retrying — smart retry uses exponential backoff (wait a bit, then a bit more) so you don't make an overloaded service worse.
Real Talk
The Retry pattern handles transient failures by automatically re-attempting a failed operation. Best practices include: maximum retry count, exponential backoff (increasing delays), jitter (randomized delays to avoid thundering herd), and idempotency requirements. Works alongside Circuit Breaker.
Show Me The Code
async function withRetry(fn, maxAttempts = 3) {
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
return await fn();
} catch (e) {
if (attempt === maxAttempts) throw e;
await sleep(2 ** attempt * 100); // exponential backoff
}
}
}
When You'll Hear This
"Add a retry with exponential backoff for the S3 upload." / "Retry three times before giving up and alerting the user."
Related Terms
Bulkhead Pattern
The bulkhead pattern isolates different parts of your system so one failure doesn't sink everything. Named after ship bulkheads that contain flooding.
Circuit Breaker
Circuit Breaker is like the electrical circuit breaker in your house.
Message Queue
A Message Queue is a waiting room for tasks. Producers drop tasks in the queue, consumers pick them up and process them one at a time.