Welcome to Pastr!

Pastr is a clean and simple pastebin, powered by Nginx, PHP, MariaDB and Redis. Credits to highlight.js, Twitter Bootstrap and FontAwesome.

Public Pastr #9365428

# Retries, Exponential Backoff and Jitter

A retry turns a transient failure into a success. A badly designed retry turns a small outage into a big one. Here is how to get retries right.

## When to retry

Retry only errors that are likely transient: timeouts, connection resets, HTTP 429/503. Do not retry 400s, auth failures, or validation errors; they will fail again. Only retry operations that are safe to repeat: reads, or writes protected by an idempotency key.

## Exponential backoff

Wait longer after each failure: base x 2^attempt (100 ms, 200 ms, 400 ms, ...), capped at a maximum such as 10 s. This gives an overloaded dependency room to recover instead of hammering it.

## Why jitter matters

If 10,000 clients fail at the same moment and all retry at exactly 100 ms, 200 ms, 400 ms, they arrive in synchronized waves. Add randomness:

- Full jitter: sleep = random(0, min(cap, base x 2^attempt))
- Equal jitter: half fixed, half random
- Decorrelated jitter: sleep = min(cap, random(base, previous_sleep x 3))

Full jitter spreads load best in most simulations and is a good default.

## Retry budgets

Limit the total retry rate, not just attempts per request. For example, retries may add at most 10 percent extra load. Without a budget, every layer of a deep call chain retrying 3 times multiplies traffic: 3 layers x 3 retries = up to 27 calls for one user request. Retry at one layer only, ideally closest to the client.

## Pair with deadlines and circuit breakers

Propagate a deadline so retries stop when the caller has already given up, and open a circuit breaker when a dependency keeps failing so retries pause entirely.

## Interview tip

When you add a retry to any design, say three things: which errors, how much backoff with jitter, and how the operation is idempotent. Interviewers notice.

Disclosure: I work on Linkjob AI (https://www.linkjob.ai/), an AI interview assistant.

⟨Abuse⟩ ⟨Contact⟩ ⟨Imprint⟩