GuideIntermediate2 min read

Timeouts, Retries, Backoff and Jitter Without Retry Storms

Build a bounded retry policy that respects caller deadlines, downstream capacity and idempotency requirements.

Author
Pradeep Gajendra
Published
Updated

Scope of this article

Environment
TypeScript function is illustrative; add external cancellation and application-specific error classification.

Retries repair transient failure, but uncontrolled retries amplify it. When the dependency is already saturated, every caller that retries immediately creates more load for a system least able to handle it. Reliability requires deadlines, attempt budgets and carefully chosen retriable operations.

Set an end-to-end deadline first#

A request with a 1.5-second total deadline cannot safely make three two-second network attempts. Partition the budget across connection establishment, server time and limited retries. Fail with a clear response when the deadline expires.

Use backoff with jitter#

retry.tstypescript
export async function retryTransient<T>(
  operation: (signal: AbortSignal) => Promise<T>,
  isTransient: (e: unknown) => boolean,
  deadlineMs = 1500,
  maxAttempts = 3,
): Promise<T> {
  const deadline = Date.now() + deadlineMs;
  let last: unknown;
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
    const remaining = deadline - Date.now();
    if (remaining <= 0) break;
    const controller = new AbortController();
    const timeout = setTimeout(() => controller.abort(), remaining);
    try {
      return await operation(controller.signal);
    } catch (error) {
      last = error;
      if (!isTransient(error) || attempt === maxAttempts - 1) throw error;
    } finally {
      clearTimeout(timeout);
    }
    const cap = Math.min(500, 100 * 2 ** attempt);
    const wait = Math.min(Math.random() * cap, Math.max(0, deadline - Date.now()));
    if (wait > 0) await new Promise<void>((resolve) => setTimeout(resolve, wait));
  }
  throw last ?? new Error("Deadline exceeded");
}

This is an illustrative retry utility. In a real library, propagate external cancellation, require idempotent operations and classify network errors carefully. Aborting a fetch does not prove that a server-side write was rolled back.

AWS recommends limiting attempts and using randomized backoff to avoid synchronized retry storms [1].

Which responses deserve a retry?#

Broad guidelines, subject to endpoint semantics

Condition

Default approach

Exception

Connection failure before send

Retry within deadline

Know whether write reached server

429 with Retry-After

Respect server delay

Do not exceed caller deadline

503 / temporary unavailability

Backoff and cap attempts

Circuit breaker may reject early

400 / invalid input

Do not retry

Only after changing request

POST after ambiguous timeout

Retry with idempotency key

Otherwise reconcile first

Prevent amplification across layers#

If a browser retries three times, the API retries three times and the worker retries three times, one user action may cause 27 downstream attempts. Place retries at a deliberate layer, and propagate a shared budget across services.

A single explicit retry policy prevents uncoordinated nested amplification.

Diagram

What to alert on#

  • Original failure rate and final failure rate, separately.

  • Retry attempts per successful operation and extra downstream request volume.

  • Deadline expirations, queue wait and p99 latency.

  • Circuit-breaker open rate, fallback usage and dependency saturation.

Sources

  1. [1]
    AWS Well-Architected — Control and Limit Retry Calls

    Amazon Web Services · publication date unknown · retrieved 2026-11-02

Spotted an error? Use “Suggest a correction” in the discussion, or read our corrections policy.

Discussion

Sign in to join the discussion. Reading is always open.

Loading discussion…

Report comment