diagram.mmd — flowchart
Request Retry Logic flowchart diagram

Request retry logic is a client-side resilience pattern that automatically re-attempts failed requests using a backoff strategy, improving success rates for transient failures without overwhelming an already-struggling upstream service.

What the diagram shows

This flowchart models the complete retry decision tree:

1. Send request: the client sends the initial request to the upstream service. 2. Evaluate response: a successful response (2xx) exits the loop immediately. 3. Classify error: not all failures are retriable. 4xx client errors (e.g., 400 Bad Request, 401 Unauthorized, 404 Not Found) indicate the request itself is malformed — retrying it won't help. 429 Too Many Requests and 5xx server errors are candidates for retry. 4. Check retry budget: the client tracks the attempt count against a configured maximum (e.g., 3 attempts). Exhausted retries surface the error to the caller. 5. Compute backoff: the wait time between retries follows exponential backoff — base * 2^attempt — with added jitter to prevent thundering herd when many clients retry simultaneously. 6. Wait and retry: after the backoff period, the request is re-attempted.

Why this matters

Without retry logic, transient network blips or brief service restarts cause user-visible errors that could be silently recovered. Without a backoff strategy, naive retries can amplify load on a struggling service — the opposite of what you want. Exponential backoff with jitter is the industry-standard approach, recommended by AWS, Google, and Netflix in their resilience guidelines.

Retries should always pair with a Circuit Breaker Pattern — once a service is known to be down, the circuit opens and retries are skipped entirely. For webhook-specific retry strategies, see Webhook Retry Strategy. The Rate Limiting Architecture explains the 429 responses that trigger retries on the server side.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

Request retry logic is a client-side resilience pattern that automatically re-attempts failed HTTP requests using a backoff strategy. It improves success rates for transient failures — network blips, brief service restarts, or temporary overloads — without requiring manual intervention or surfacing spurious errors to the user.
After a failed request, the client first classifies the error: 4xx client errors (400, 401, 404) are not retriable because retrying won't fix a malformed request. 5xx server errors and 429 responses are candidates for retry. If the attempt count is below the configured maximum, the client waits for an exponential backoff period — base delay multiplied by 2 to the power of the attempt number — plus a random jitter value, then re-sends the request.
Always use backoff with jitter for any retry logic in production. Backoff prevents a struggling service from being immediately hammered with retries. Jitter — random variation in the wait time — prevents the thundering herd effect, where many clients all backed off for the same duration and simultaneously retry at the same moment, creating a traffic spike at a predictable interval.
A common mistake is retrying 4xx responses — a 400 Bad Request will never succeed no matter how many times it is retried. Another frequent error is not setting a maximum retry count, creating an infinite retry loop. Teams also forget to make the operation being retried idempotent — if a charge request is retried after the first attempt succeeded but the response was lost, the customer may be double-charged.
mermaid
flowchart TD A([Send request]) --> B{Response received?} B -- No response / timeout --> C[Classify as retriable error] B -- Response received --> D{HTTP status code} D -- 2xx Success --> E([Return success to caller]) D -- 4xx Client Error --> F([Return error - do not retry]) D -- 429 Too Many Requests --> C D -- 5xx Server Error --> C C --> G{Retry budget remaining?} G -- No retries left --> H([Return final error to caller]) G -- Retries available --> I[Increment attempt counter] I --> J[Compute exponential backoff with jitter] J --> K[Wait backoff duration] K --> L[Re-send request] L --> B
Copied to clipboard