Skip to content

Lesson 5 of 9 · 25m

Retries, Backoff, and Dead Letters That Operators Can Survive

Design retry schedules with jitter, classify failures honestly, bound retry storms, and quarantine poison messages without losing them.

A naive retry loop is a denial-of-service bot you built against your customers and yourself. I have watched a single expired TLS certificate turn 200 webhook endpoints into a synchronized retry storm: every worker retried at the same minute, queues backed up, live events aged behind dead ones, and the recovery created a second outage. Retries need cadence, randomness, memory, and an exit ramp.

Classify response outcomes correctly

HTTP status is evidence, not a complete verdict:

2xx        delivered; consumer accepted responsibility
408, 409, 425, 429   retryable, often with consumer-provided delay
5xx        retryable
network timeout, DNS failure, TLS failure   retryable
400, 401, 403, 404, 410, 422   usually permanent until configuration changes

The dangerous exception is ambiguity. A timeout after the consumer processed the request is a duplicate risk, which is why idempotency exists. A 409 might mean duplicate accepted or a business conflict; do not blindly treat it as success unless your contract says so. Stripe-style webhook systems often retry most non-2xx responses, but your own integration can be more precise if it controls the consumer semantics.

Exponential backoff needs jitter

A reasonable schedule is exponential growth capped at minutes or hours, with random jitter:

base = min(3600, 15 * (2 ** min(attempt, 8)))
delay = random.uniform(0.5 * base, 1.5 * base)
next_retry_at = now + timedelta(seconds=delay)

Without jitter, all deliveries for a failing endpoint retry in lockstep. With no cap, queues fill with ancient retries. With no randomness in worker scheduling, deploys can accidentally synchronize thousands of tasks.

Retry budgets are endpoint-scoped and event-scoped

Do not let one dead endpoint consume capacity needed by healthy tenants. Apply concurrency and rate limits per endpoint and per customer account. Give high-priority fresh events separate workers or weighted queues from old retries. Otherwise an endpoint down for six hours becomes a six-hour traffic avalanche when it recovers.

Dead letters are a holding pen, not a trash can

After the retry budget ends — perhaps 24 to 72 hours depending on business criticality — move the delivery to a dead-letter state. Preserve the signed payload, full attempt history, last response status, response body excerpt, TLS/DNS error, and a replay control:

UPDATE webhook_deliveries
   SET state = 'dead_lettered', dead_at = now()
 WHERE id = $1
   AND attempt >= max_attempts;

Operators need bulk replay after endpoint recovery, but replay must be deliberate and rate limited. Blindly replaying 100,000 stale events can corrupt consumer ordering assumptions or overload their system.

Respect retry hints when available

If a consumer returns Retry-After: 120, honor it within reasonable bounds. If the consumer implements exponential backoff on its own queues, your delivery layer backing off too aggressively may not be harmful, but ignoring explicit hints is rude and operationally expensive.

Field notes

  • Measure webhook age at successful delivery, not just delivery count. A 99 percent success rate with a four-hour tail can still be a customer-visible outage.
  • Include delivery attempt count in internal logs, not necessarily in public headers consumers might misuse.
  • Alert on retry backlog growth and oldest pending age before alerting on dead letters; dead letters mean you already lost timeliness.
  • Cancellation matters. If an endpoint is disabled, stop future attempts and mark pending deliveries canceled rather than retrying forever.
  • A manual redrive is a new delivery attempt of the same logical event, not a mutation of history. Keep the original failure evidence.

Was this lesson helpful?

Sign in to rate