A developer reviewing API requests and service reliability on a laptop

Editorial illustration; it does not depict a specific production system.

Published on 18 October 2026.

An API call times out. Your code catches the error, waits a second, and fires the exact same request again. On a quiet Tuesday, that looks like resilience. During a brief upstream hiccup, when hundreds of users or background workers do it at the same time, you turn a 5-second blip into a self-inflicted DDoS—or worse, you charge a customer twice.

Retries are a sharp tool. Done well, they smooth over transient network drops; done lazily, they amplify outages and corrupt state.

Know which failures are worth retrying

Never write a catch block that retries every error. A 400 Bad Request, 401 Unauthorized, or 403 Forbidden will not magically succeed on the third attempt—your payload or credentials are wrong, so fail fast and log it.

Save retries for genuinely transient failures:

  • Network-level timeouts and connection resets (ECONNRESET, ETIMEDOUT)
  • Upstream gateway or overload responses (502, 503, 504, and sometimes 500)
  • Rate limits (429 Too Many Requests), provided you respect the Retry-After header

Check the API’s own documentation too. Some payment or government APIs return 200 OK with an error code inside the JSON body, or use 500 for a permanent business rule failure. And remember the golden rule of distributed systems: a timeout does not prove the server never received your request. It may have finished processing right before the socket dropped.

Cap both the attempt and the total deadline

A retry loop without timeouts is how you exhaust every worker thread or connection pool in your app. Always set two boundaries:

  • Per-attempt timeout: How long a single HTTP call is allowed to hang (for example, 1500ms for an interactive lookup).
  • Total caller deadline: The maximum wall-clock time the whole operation may take (for example, 5000ms for a web request, or 30s for a background sync job).

If a user-facing endpoint only has a 5-second budget, do not configure four retries with 4-second timeouts each. Once the deadline expires, stop retrying and return a clear status—or push the work onto a background queue—rather than keeping the browser spinning.

Spread clients out with exponential backoff and jitter

Retrying immediately hammers a service at the exact moment it is trying to recover. Exponential backoff increases the wait between attempts (200ms, 400ms, 800ms, 1600ms), giving the upstream breathing room.

Even with backoff, fixed delays have a flaw: if 500 workers time out together at 12:00:00 and all wait 1000ms, they will hit the server in a synchronised wave at 12:00:01. Adding jitter (randomness) spreads those retries out. Full jitter—picking a random delay between 0 and min(maxDelay, baseDelay * 2^attempt)—is simple and effective.

If the server sends a Retry-After header (either seconds or an HTTP date), honour it as long as it fits inside your total deadline. And remember that retries do not fix chronic rate limiting: if you are hitting 429 constantly, you need caching, request batching, or a higher quota, not a longer sleep loop.

Never retry blind writes without idempotency

Retrying a GET request is usually safe because reading data does not create duplicate records. Retrying a POST that creates an order, sends an email, or triggers a payment is dangerous unless the endpoint supports idempotency.

With an idempotency key, your client generates a unique UUID per logical action and sends it in a header (such as Idempotency-Key). If the request times out and your client retries with the same key, the server recognises it and returns the original result instead of charging the card a second time.

If the third-party API does not support idempotency keys, do not auto-retry the write on a timeout. Instead, query the status of the operation using a client-generated reference ID, or surface an honest "unknown_outcome" state so the user or support team checks before trying again.

Keep retries at one clear layer

Retry amplification happens silently when multiple layers each add their own loop: the browser retries, your C# or Node API client retries via Polly or axios-retry, and your background job runner retries the whole job. Three attempts at three layers equals twenty-seven requests for one user click.

Pick one owner for retries and document it. Put transport-level retries in your shared HTTP client, and handle business-level recovery in the workflow layer. Here is a minimal TypeScript pattern showing bounded attempts, per-attempt timeout, Retry-After support, and full jitter:

async function fetchWithRetry(url: string, options: RequestInit = {}, maxAttempts = 3) {
  const deadline = Date.now() + 5000;

  for (let attempt = 0; attempt < maxAttempts; attempt++) {
    const remaining = deadline - Date.now();
    if (remaining <= 0) break;

    try {
      const res = await fetch(url, {
        ...options,
        signal: AbortSignal.timeout(Math.min(1500, remaining)),
      });

      if (res.ok) return res;
      if (![429, 502, 503, 504].includes(res.status)) {
        throw new Error(`Non-retryable status: ${res.status}`);
      }

      const retryAfterSec = Number(res.headers.get("Retry-After"));
      const cap = Math.min(2000, 200 * 2 ** attempt);
      const waitMs = Number.isFinite(retryAfterSec) && retryAfterSec > 0
        ? retryAfterSec * 1000
        : Math.random() * cap;

      if (Date.now() + waitMs >= deadline) break;
      await new Promise((r) => setTimeout(r, waitMs));
    } catch (err) {
      if (attempt === maxAttempts - 1 || Date.now() >= deadline) throw err;
    }
  }

  throw new Error("Retry budget exhausted");
}

When retries are exhausted, log the attempt count, status codes, and correlation ID (without leaking auth tokens or PII), and distinguish between a confirmed rejection and an unknown outcome. Finally, test your retry code against a mock server that injects 429 responses and 3-second hangs—a happy-path unit test will never prove your backoff actually works under pressure.

For related guides that complement this checklist, see:

Good retry logic is deliberately boring: a small attempt cap, a hard deadline, a bit of random jitter, and strict idempotency for anything that mutates state. Knowing when to stop retrying is what keeps a minor upstream wobble from taking your own app down with it.

Sources