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
- Always combine with idempotency — Use the
Idempotency-Keyheader to prevent duplicate transactions on retries - Limit retries — 3–5 retries is sufficient. Beyond that, the error is likely permanent
- Add jitter — Random variation prevents all clients from retrying at the same time
- Respect
Retry-After— If the header is present, use its value instead of your calculated delay - Log all retries — Keep audit logs for debugging and monitoring
Idempotency Guide
Learn how idempotency keys prevent duplicate transactions during retries.

