Network timeouts, provider outages, and rate limits are common in payment systems. A well-designed retry strategy maximizes your success rate without overloading the system.

When to retry

Retry (5xx)

500, 502, 503, 504 — Server errors are usually temporary.

Retry with caution (429)

429 Too Many Requests — Respect the Retry-After header.

Do NOT retry (4xx)

400, 401, 403, 404, 422 — Client errors won’t resolve with retries.

Exponential backoff

Increase the delay between retries progressively to give the system time to recover:

Implementation

Complete example: payment with retry + idempotency

Best practices

  1. Always combine with idempotency — Use the Idempotency-Key header to prevent duplicate transactions on retries
  2. Limit retries — 3–5 retries is sufficient. Beyond that, the error is likely permanent
  3. Add jitter — Random variation prevents all clients from retrying at the same time
  4. Respect Retry-After — If the header is present, use its value instead of your calculated delay
  5. Log all retries — Keep audit logs for debugging and monitoring

Idempotency Guide

Learn how idempotency keys prevent duplicate transactions during retries.