A good retry policy answers five questions: should I retry, how long should I wait, how many times, at which layer, and when do I give up? The server's Retry-After header answers only part of one of them.
AI disclosure. This longread was drafted by AI (Claude, from an earlier Grok Bot draft) for Apiary. It has not been reviewed or verified by the founder. Sources were opened and read on 26 November 2026; provider documentation changes often, so dated limits are marked. Worked examples are hypothetical.
Retrying a failed request is one of the cheapest reliability tools there is. AWS's Builders' Library notes that "a surprisingly large number of transient or random faults can be overcome by simply retrying the call" (Featonby, AWS Builders' Library). It is also one of the easiest to get wrong. The same library warns that "retries are 'selfish.' In other words, when a client retries, it spends more of the server's time to get a higher chance of success," and that "when failures are caused by overload, retries that increase load can make matters significantly worse" (Brooker, AWS Builders' Library, "Timeouts, retries, and backoff with jitter").
A sound strategy, drawn from the sources in this article, has six parts: retry only errors that can succeed later; make sure a repeat is safe; wait longer after each failure, with randomness; honor what the server says about timing, in both of the formats HTTP allows; cap attempts, total time and the share of traffic that is retries; and retry at one layer only. The Retry-After header deserves special care because it is easy to misread. It tells you how long to wait. It does not tell you that waiting will help, that the request is safe to repeat, or that a response without it means "try again now."
This page replaces an earlier Apiary page of the same name. That page contained several figures that could not be traced to a source and a code sample that mishandles one of Retry-After's two legal forms; the corrections are listed in section 15.
1. The five decisions a retry policy makes
Microsoft's Azure Architecture Center describes three basic responses to a failure: cancel ("if the fault indicates that the failure isn't transient or is unlikely to be successful if repeated"), retry immediately (for something "unusual or rare, like a network packet becoming corrupted"), and retry after delay, where the delay "should be chosen to spread requests from multiple instances of the application as evenly as possible" (Microsoft Learn, Retry pattern).
Expanding that into the decisions a policy must make:
| Decision | Question | Sections below |
|---|---|---|
| Eligibility | Is this error one that can succeed later, and is a repeat safe? | 2, 3 |
| Delay | How long to wait before the next attempt? | 4, 5, 6 |
| Limits | How many attempts, how much total time, how much retry traffic overall? | 7, 9 |
| Placement | Which layer of the system retries? | 8 |
| Exit | What happens when retrying stops? | 7, 13 |
Microsoft also stresses that the right answers depend on context: "For some noncritical operations, it's better to fail fast rather than retry several times," while "for a batch application, it might be more appropriate to increase the number of retry attempts" (Microsoft Learn, Retry pattern). A chat interface waiting on a person and an overnight batch job should not share a policy.
2. Retry only errors that can succeed later
The first filter is the error itself. Brooker's article summarizes the HTTP convention: HTTP "indicates that client errors should not be retried with the same request because they aren't going to succeed later, while server errors may succeed on subsequent tries" (Brooker, AWS Builders' Library). Microsoft gives the plain example: "if a client application receives a 400 Bad Request error response, retrying the same request likely won't help because the server has already informed you that your request isn't valid" (Microsoft Learn, Retry Storm antipattern).
In practice, major client libraries publish explicit lists. As documented on 26 November 2026:
| Library or service | Retried by default |
|---|---|
| Google Cloud Storage tools | "HTTP 408, 429, and 5xx response codes" and "socket timeouts and TCP disconnects" (Google Cloud, Retry strategy) |
| AWS SDKs (new 2026 behavior) | Transient errors such as RequestTimeout, InternalError, I/O failures, and "any HTTP 500, 502, 503, or 504 without a recognized error code"; throttling errors such as ThrottlingException, TooManyRequestsException and SlowDown. Errors such as AccessDeniedException and ValidationException "are returned to your code immediately" (AWS SDKs and Tools Reference Guide, Retry behavior) |
| Anthropic SDKs | Unless an x-should-retry header says otherwise, "connection errors, timeouts, and the statuses 408, 409, 429, and 500 and above" (Anthropic, API errors) |
| OpenAI SDKs | "Each official OpenAI SDK automatically retries eligible 429 and 503 responses, subject to its retry settings" (OpenAI, Rate limits) |
Three refinements matter.
Status codes are not enough. AWS classifies by error code first: "an HTTP 400 with the error code RequestTimeout is classified as transient and retried. An HTTP 400 with ValidationException is classified as non-retryable" (AWS SDK Retry behavior). Anthropic and OpenAI both return HTTP 429 for conditions that waiting will not fix, such as monthly spend caps (see section 6 and the companion article on rate limits versus spending limits). OpenAI's error guide says flatly: "Retrying billing, spend, or quota errors won't restore API access" (OpenAI, Error codes).
Eventual consistency blurs the line. Brooker notes that "a client error one moment may change into a success the next moment as state propagates" (Brooker, AWS Builders' Library). A 404 immediately after creating a resource in a different region may be real or may be lag. Treat such cases explicitly rather than retrying every 4xx.
Servers can tell you directly. Some APIs send an explicit retry hint. Stripe's Stripe-Should-Retry header means, when true, "retry the request using exponential backoff"; when false, "don't retry the request"; and when absent, use "the status code and other response information" (Stripe, Advanced error handling). Anthropic documents an x-should-retry header that its SDK follows when present, and advises for a 500: "Retry only if the response's x-should-retry header isn't false" (Anthropic, API errors). Where such a header exists, it should override your own guess.
3. Make sure a repeat is safe
An eligible error does not make a request safe to repeat. RFC 9110 sets the rule for HTTP: "A client SHOULD NOT automatically retry a request with a non-idempotent method unless it has some means to know that the request semantics are actually idempotent, regardless of the method, or some means to detect that the original request was never applied" (RFC 9110 §9.2.2, June 2022). AWS's view is the same: "APIs with side effects aren't safe to retry unless they provide idempotency" (Brooker, AWS Builders' Library).
Google Cloud Storage makes this concrete with three categories. Some operations are "always idempotent" (all get and list requests, for example). Some are "conditionally idempotent," meaning "they are only idempotent if they include specific optional arguments" such as a generation-match precondition. Some are "never idempotent," such as creating a Pub/Sub notification, "because it creates a new notification ID each time the request succeeds" (Google Cloud, Retry strategy). Its guidance is that "operations that are conditionally safe to retry should only be retried by default if the condition case passes."
For creates and payments, the usual tool is an idempotency key. The companion article biggie-idempotency-in-apis covers how keys work, what the server stores and how windows expire. The short version for a retry policy: generate the key once per operation, reuse it on every attempt, and do not retry a non-idempotent request without one.
4. Exponential backoff, capped
Immediate retries against a struggling service mostly add load. The standard alternative is exponential backoff. Stripe's engineering blog describes it: "The client blocks for a brief initial wait time on the first failure, but as the operation continues to fail, it waits proportionally to 2^n, where n is the number of failures that have occurred" (Leach, Stripe blog, 2017). Brooker adds the necessary cap: "Exponential backoff can lead to very long backoff times, because exponential functions grow quickly. To avoid retrying for too long, implementations typically cap their backoff to a maximum value. This is called, predictably, capped exponential backoff" (Brooker, AWS Builders' Library).
Published defaults differ widely, which is itself useful information. As documented on 26 November 2026:
| Implementation | Documented backoff |
|---|---|
| AWS SDKs, standard mode (opt-in 2026 behavior) | delay = random(0, 1) × min(20,000 ms, base_delay × 2^retry), with a base of 50 ms for transient errors and 1,000 ms for throttling (AWS SDK Retry behavior) |
| Google Cloud Storage C++ client | Initial wait 1 second, multiplier 2, maximum wait 5 minutes (Google Cloud, Retry strategy) |
| Google Cloud Storage Go client | Multiplier 2.0, maximum retry delay 30 seconds (Google Cloud, Retry strategy) |
| Anthropic SDKs | Without a retry-after header, "exponential backoff from 0.5 to 8 seconds" (Anthropic, API errors) |
Two observations follow. First, the AWS SDK's split between a short base for transient errors and a long base for throttling encodes a real difference: AWS explains that throttling means "the service actively rejected your request due to rate limits, so the SDK waits longer before retrying to give the service time to recover capacity" (same source). Second, the AWS page carries a dated caveat: the behavior it describes "requires opting in until it becomes the default behavior" by setting AWS_NEW_RETRIES_2026=true; "without this setting, your SDK uses pre-2026 retry behavior, which differs in backoff timing, retry quota costs, and service-specific defaults" (AWS SDK Retry behavior). Library defaults change; check the version you actually run.
Capping creates its own issue. Brooker notes that with a cap, "all of the clients are retrying constantly at the capped rate," and that the usual fix is "to limit the number of times that the client retries" (Brooker, AWS Builders' Library). Backoff and attempt limits work together; neither is enough alone.
5. Jitter: why randomness helps
Backoff alone leaves a problem: clients that failed together retry together. Stripe's blog calls this "the thundering herd problem": "If a problem with a server causes a large number of clients to fail at close to the same time, then even with back off, their retry schedules could be aligned closely enough that the retries will hammer the troubled server" (Leach, Stripe blog, 2017). Google's SRE book makes the same point: "If retries aren't randomly distributed over the retry window, a small perturbation (e.g., a network blip) can cause retry ripples to schedule at the same time, which can then amplify themselves" (Ulrich, Site Reliability Engineering, ch. 22).
The best-known evidence is a 2015 AWS Architecture Blog post by Marc Brooker, which simulated many clients competing to update one row in a database using optimistic concurrency. It is an observed result from a simulation, not a measurement of production traffic. Brooker found that plain exponential backoff "helps a small amount, but doesn't solve the problem," because "there are still clusters of calls." Adding randomness to the sleep removed the gaps: "In the case with 100 contending clients, we've reduced our call count by more than half" (Brooker, AWS Architecture Blog, 4 March 2015, updated May 2023).
The post compared three jitter variants. "Full Jitter" picks a random wait between zero and the backoff value. "Equal Jitter" keeps half the backoff and randomizes the rest, which "prevents very short sleeps." "Decorrelated Jitter" grows the random range based on the previous wait. The results: "the number of calls is approximately the same for 'Full' and 'Equal' jitter, and higher for 'Decorrelated'. Both cut down work substantially relative to both the no-jitter approaches"; "The no-jitter exponential backoff approach is the clear loser"; and of the jittered approaches, Equal Jitter "does slightly more work than 'Full Jitter', and takes much longer" (same source). Brooker is careful about scope: "none of these approaches fundamentally change the N2 nature of the work to be done, but do substantially reduce work at reasonable levels of contention."
The post's May 2023 update says that "after 8 years, this solution continues to serve as a pillar for how Amazon builds remote client libraries," and that "most AWS SDKs now support exponential backoff and jitter as part of their retry behavior when using standard or adaptive modes" (same source). The current AWS SDK documentation confirms full jitter: "The SDK uses exponential backoff with full jitter" (AWS SDK Retry behavior). gRPC applies a narrower band: "Jitter of plus or minus 20% is applied to the backoff delay to avoid hammering servers at the same time from a large number of clients" (gRPC, Retry guide).
A subtlety from Brooker's Builders' Library article: for scheduled work (periodic jobs, timers), AWS does not pick jitter randomly on each run. "We use a consistent method that produces the same number every time on the same host. This way, if there is a service being overloaded, or a race condition, it happens the same way in a pattern" (Brooker, AWS Builders' Library). He reports that on Amazon EBS and AWS Lambda, clients that sent requests "once per minute" tended to line up, and that "by paying attention to per-second load, and working with clients to jitter their periodic workloads, we accomplished the same amount of work with less server capacity" (same source). For retries after a failure, random jitter remains the norm.
6. Retry-After: what the server is telling you
What the standard says
RFC 9110 defines the header: "Servers send the 'Retry-After' header field to indicate how long the user agent ought to wait before making a follow-up request." With a 503, "Retry-After indicates how long the service is expected to be unavailable to the client." Its value "can be either an HTTP-date or a number of seconds to delay after receiving the response," with the examples Retry-After: Fri, 31 Dec 1999 23:59:59 GMT and Retry-After: 120, where "the delay is 2 minutes" (RFC 9110 §10.2.3). The 503 status itself means "the server is currently unable to handle the request due to a temporary overload or scheduled maintenance," and the server "MAY send a Retry-After header field" (RFC 9110 §15.6.4). For 429, RFC 6585 says the response "MAY include a Retry-After header indicating how long to wait before making a new request," and gives the example Retry-After: 3600 (RFC 6585 §4, April 2012).
Note the word "MAY" in both places. Servers are not required to send the header, and the RFC's own note on 503 adds that "the existence of the 503 status code does not imply that a server has to use it when becoming overloaded. Some servers might simply refuse the connection" (RFC 9110 §15.6.4).
What it does not say
- It is not a promise of success. It is the server's estimate of when trying again is worthwhile.
- It does not make a request safe to repeat. A 503 on a POST that may have partly run still needs idempotency protection or a status check.
- Its absence is not permission to retry immediately. Anthropic's documentation states that the
retry-afterheader gives "the number of seconds to wait until you can retry the request. Earlier retries might fail. Not every 429 carries it; the spend-cap 429 never does" (Anthropic, Rate limits). OpenAI's rate-limit guide saysRetry-After"may be present on429responses caused by a temporary rate limit and503responses caused by temporary model overload. It does not mean that quota, billing, or other errors that require user action can be resolved by retrying" (OpenAI, Rate limits).
How providers want it used (vendor guidance, 26 November 2026)
OpenAI: "Treat this value as a minimum: wait at least that long and add a small random delay so multiple clients don't retry at the same time." If "a valid server delay exceeds the supported or configured maximum retry delay, stop retrying and defer the request rather than retrying sooner." If the header is "missing or invalid, fall back to exponential backoff with jitter" (OpenAI, Rate limits). Microsoft: "If the server provides a retry-after response header, don't attempt to retry until the specified time period passes" (Microsoft Learn, Retry Storm antipattern). Anthropic's SDK: "If the response has a retry-after header, the SDK waits as long as the header says. Otherwise, it uses exponential backoff from 0.5 to 8 seconds" (Anthropic, API errors).
Some services use their own header. AWS documents that "some AWS services include an x-amz-retry-after header in error responses. The header value is a delay in milliseconds" — not seconds. The AWS SDK clamps it between the computed backoff and the computed backoff plus 5,000 ms, so "the effective maximum server-directed delay is 25 seconds," and "the SDK does not apply jitter to this value, because the service is expected to jitter it" (AWS SDK Retry behavior). Unit mismatches between seconds and milliseconds are an easy bug.
Parsing both forms
The earlier version of this page parsed the header with int(response.headers.get('Retry-After', '1')). That line has two problems. It raises an exception on the HTTP-date form, which RFC 9110 explicitly allows. And its default of one second turns "the server gave no timing hint" into "retry in one second," which is exactly the behavior the provider guidance above warns against for spend caps and quota errors.
OpenAI's own TypeScript example in its rate-limit guide handles both forms: it reads the header, tries Number(hint) * 1000, falls back to Date.parse(hint) - Date.now() if that is not a number, treats a negative or unparseable result as "no hint," and returns "undefined" (stop) for delays over its 60-second budget or for quota codes such as insufficient_quota and billing_hard_limit_reached (OpenAI, Rate limits). An equivalent language-neutral procedure (editorial suggestion):
- If the header is absent, fall through to the error-code check and normal backoff; do not invent a default.
- If it is all digits, treat it as seconds.
- Otherwise try to parse it as an HTTP-date and subtract the current time; clamp negatives to zero.
- If neither works, ignore it and use normal backoff.
- Use the larger of the server's delay and your computed backoff, plus a little jitter.
- If the result exceeds your job's budget, stop and reschedule rather than retrying early.
7. Limit attempts and total time
Every source in this article recommends a hard limit. Google SRE: "Limit retries per request. Don't retry a given request indefinitely" (Ulrich, SRE ch. 22). Microsoft: "Writing a while(true) loop might seem simple, but you usually don't want to retry for a long period of time. The conditions that led to the request being initiated likely changed. Most applications only need to retry for a few seconds or minutes" (Microsoft Learn, Retry Storm antipattern). OpenAI: "Limit both the number of attempts and the total time spent retrying" (OpenAI, Rate limits).
Documented defaults, as of 26 November 2026:
| Implementation | Default attempts |
|---|---|
| AWS SDKs | "A max attempts value of 3 means the SDK makes one initial request and up to two retries"; DynamoDB clients "default to 4 max attempts" (AWS SDK Retry behavior) |
| Anthropic SDKs | "Up to two times (three attempts in all)," configurable with max_retries (Anthropic, API errors) |
| Google internal practice (SRE book, ch. 21) | "A per-request retry budget of up to three attempts" (Forero Cuervo, SRE ch. 21) |
| gcloud CLI for Cloud Storage | "The default number of maximum retries is 32" (Google Cloud, Retry strategy) |
The gcloud figure shows that "three" is not a law. A command-line upload tool that a person starts and watches can reasonably try much harder than a request handler inside a busy web server. What matters is that the limit is chosen deliberately.
Attempt counts are not the only budget. A request also has a deadline: the point after which no one is waiting for the answer. Google's SRE book describes "deadline propagation," in which "a deadline is set high in the stack" and every downstream call inherits the remaining time; in its example, a 30-second deadline at server A leaves 23 seconds for server B after 7 seconds of work (Ulrich, SRE ch. 22). A retry loop should check the remaining deadline before each attempt. OpenAI's guide adds a useful distinction: "A timeout for each attempt isn't necessarily a deadline for the entire operation" (OpenAI, Rate limits).
8. Retry at one layer
Retries multiply across layers. Brooker's example: "a five-deep stack of service calls" with "three retries at each layer"; if the database fails under load, "the load on the database will increase 243x, making it unlikely to ever recover." AWS's practice is "to retry at a single point in the stack" (Brooker, AWS Builders' Library). Google's SRE book gives a smaller version: if "the backend, frontend, and JavaScript layers all issue 3 retries (4 attempts), then a single user action may create 64 attempts (4^3) on the database" (Ulrich, SRE ch. 22). Both are worked arithmetic, not measurements, but the arithmetic is unavoidable.
The SRE book's handling-overload chapter states the rule for deep stacks: "requests should only be retried at the layer immediately above the layer that is rejecting them," and a layer that decides a request should not be retried returns an "overloaded; don't retry" error "and thus avoid a combinatorial retry explosion" (Forero Cuervo, SRE ch. 21). Microsoft gives the same advice in application terms: if a task with a retry policy calls another task that also retries, "it might be better to configure the lower-level task to fail fast and report the reason for the failure back to the task that invoked it" (Microsoft Learn, Retry pattern).
The most common modern instance is a hand-written retry loop around an SDK that already retries. OpenAI's guide addresses it directly: "If you manage retries in your application, disable SDK retries or account for them in those limits so nested retry loops don't multiply requests," and its own examples set maxRetries: 0 on the client for that reason (OpenAI, Rate limits).
9. Retry budgets: a limit on the whole client
Per-request limits do not stop a large fleet from producing a large volume of retries. A retry budget caps retries as a share of all traffic.
- Google: "Consider having a server-wide retry budget. For example, only allow 60 retries per minute in a process, and if the retry budget is exceeded, don't retry; just fail the request" (Ulrich, SRE ch. 22). The overload chapter describes a per-client budget in which "a request will only be retried as long as this ratio is below 10%," and works through why: with only a three-attempt cap, a mostly rejecting datacenter could see requests grow "to somewhere just below 3X," but "layering on the per-client retry budget (a 10% retry ratio) reduces the growth to just 1.1x in the general case" (Forero Cuervo, SRE ch. 21).
- AWS SDKs: Standard mode "includes a retry quota, a token bucket that deducts tokens for each retry and replenishes tokens when requests succeed. When the available tokens are exhausted, the SDK returns the error without retrying." The documented parameters for the 2026 behavior are a capacity of 500 tokens, a cost of 14 tokens per transient retry and 5 per throttling retry, and 1 token restored for a first-try success. AWS says that with default settings "the quota begins to drain when more than approximately 22% of requests result in sustained transient failures, or more than approximately 32% for throttling errors" (AWS SDK Retry behavior). Brooker's article says this kind of local token-bucket limit is behavior "AWS added ... to the AWS SDK in 2016" (Brooker, AWS Builders' Library).
- gRPC: "For each server, the gRPC client tracks a token_count (initially set to maxTokens). Failed RPCs decrement the count by 1, successful RPCs increment it by tokenRatio. If the token_count falls below half of maxTokens, retries are paused until the count recovers" (gRPC, Retry guide).
The AWS documentation explains why transient retries cost more than throttling retries in its design: transient errors "often indicate a service-wide problem," where "continued retrying is unlikely to succeed," whereas throttling errors "signal that the service needs more time" (AWS SDK Retry behavior). It also notes a scope limit: the budget "is not shared across processes or hosts." A fleet of a thousand processes has a thousand budgets.
10. Slowing down before the server says no
Retry policies react to failures. Some clients also shape traffic in advance.
Adaptive client-side throttling. Google's SRE book describes a technique in which each client tracks, over two minutes, how many requests it attempted and how many the backend accepted. "Clients can continue to issue requests to the backend until requests is K times as large as accepts. Once that cutoff is reached, the client begins to self-regulate and new requests are rejected locally" with a calculated probability. Google reports, as an observed result from its own operation, that "we've found adaptive throttling to work well in practice, leading to stable rates of requests overall" (Forero Cuervo, SRE ch. 21).
AWS adaptive mode "includes everything in standard mode, plus a client-side rate limiter" that "tracks throttling responses and adjusts the rate at which the SDK sends requests," and "can delay or block the initial request, not just retries." AWS recommends it when a client "targets a single resource ... and you expect frequent throttling responses," noting this "is common in automated workflows, batch processors, or AI workloads that call a single API operation at high volume," but says it "is not recommended as a general default" because throttling on one resource slows all requests from that client (AWS SDK Retry behavior).
Reading quota headers. Many APIs report remaining capacity. Anthropic returns headers such as anthropic-ratelimit-requests-remaining and anthropic-ratelimit-requests-reset, with the reset time "provided in RFC 3339 format" (Anthropic, Rate limits). OpenAI documents x-ratelimit-remaining-requests, x-ratelimit-remaining-tokens and reset durations such as 6m0s (OpenAI, Rate limits). An IETF working draft (revision 12, published 20 November 2026) proposes standard RateLimit-Policy and RateLimit fields "allowing clients to shape their requests to avoid exceeding server-imposed limits" (IETF draft-ietf-httpapi-ratelimit-headers-12); it is a draft, not a standard.
Ramping gradually. Both large AI providers now document limits on how fast traffic may grow. Anthropic's "ramp limit caps how fast your organization's token usage on a model can grow," and advises starting "scheduled or bulk jobs at a low rate" (Anthropic, Rate limits). OpenAI's slow_down error "can occur even when your traffic is within its requests-per-minute and tokens-per-minute limits," and its rule of thumb is that "once your traffic reaches 1 million input tokens per minute (TPM), increase it by no more than 50% every 15 minutes" (OpenAI, Rate limits). Both are vendor guidance dated 26 November 2026.
One more OpenAI note bears directly on retry loops: "unsuccessful requests contribute to your per-minute limit, so continuously resending a request won't work" (same source).
11. Timeouts are part of the strategy
A retry policy is only as good as the timeout that triggers it. Brooker describes the tradeoff: a timeout set too high "reduces its usefulness, because resources are still consumed while the client waits," while one set too low risks "increased traffic on the backend and increased latency because too many requests are retried" and even "a complete outage, because all requests start being retried." AWS's starting point inside a region is to choose "an acceptable rate of false timeouts (such as 0.1%)" and set the timeout at the matching latency percentile of the downstream service, p99.9 in that example (Brooker, AWS Builders' Library).
He also reports a failure from his own work: a 20-millisecond timeout that caused errors only after deployments, because "the timer included establishing a new secure connection." The fix was to establish connections "when a process started up, but before receiving traffic" (same source). The lesson is to know what your timeout actually measures, since some implementations, Brooker notes, do not cover "DNS or TLS handshakes."
12. Streams and partly delivered results
Streaming responses add a case simple retry logic misses: the request succeeded at first and failed partway. OpenAI's guide says HTTP error responses "apply before the stream starts," while "an error after streaming begins can arrive as a stream event; don't automatically replay a request after consuming output" (OpenAI, Rate limits). Anthropic's documentation says that "the SDK doesn't retry an error in a stream" and that an error can occur "after the API returns a 200 response" (Anthropic, API errors). gRPC formalizes the cutoff: "Once the response header is received, the RPC is committed. No further retries will be attempted" (gRPC, Retry guide).
For AI applications, the editorial suggestion is to treat a mid-stream failure as a distinct state. You may already have shown text to a user, written part of a file or triggered a tool call. Decide explicitly whether to discard, resume or restart, rather than letting a generic retry wrapper resend the whole request.
13. Logging and stopping cleanly
Microsoft recommends a logging pattern that keeps alerts meaningful: "log early failures as informational entries and only the failure of the last of the retry attempts as an actual error" (Microsoft Learn, Retry pattern). It also advises logging "all connectivity failures that cause a retry so that underlying problems with the application, services, or resources can be identified" (same source). gRPC exposes retry metrics through OpenTelemetry for the same purpose (gRPC, Retry guide).
Google's SRE book warns that "graphs of retry rates can be an indication of bad retry behavior, but may be confused as a symptom instead of a compounding cause" (Ulrich, SRE ch. 22). Recording attempt counts separately from first attempts makes that distinction visible.
A clean stop means the job records what it was doing, why it stopped (attempt limit, deadline, budget, non-retryable error, server delay beyond budget) and what remains, so a person or a later run can pick up without guessing. A useful minimum record per failed operation (editorial suggestion): operation ID and idempotency key, attempt count, each status and error code, any Retry-After or retry-hint header, the final reason for stopping, and whether the outcome is known or unknown.
14. Worked example: an article-summarizing job (hypothetical)
This example is hypothetical. The job, numbers and timings are invented; the provider behaviors it reacts to are the documented ones cited above.
A nightly job sends 400 articles to a language-model API for summaries, then writes each summary to a database.
Policy. The job uses the provider's SDK with its built-in retries turned off, so there is exactly one retry layer: the job's own. Each request gets at most four attempts and a two-minute total budget. Delays follow full jitter with a 1-second base and a 30-second cap. A Retry-After value, parsed in either form, sets a floor; if it exceeds the remaining budget, the article is deferred to the next run. A job-wide budget stops all retries if more than 10 percent of recent requests are retries. Error codes for spend caps or quota stop the whole job immediately. Writes to the database use the article ID as a natural key, so a repeated write replaces rather than duplicates.
Run. At article 120, three requests in a row get 429 with retry-after: 20. Each waits 20 seconds plus up to 2 seconds of random jitter and succeeds. At article 260, a 529 overload response with no retry-after arrives; the job backs off 0–1 s, 0–2 s, 0–4 s, and the third retry succeeds. At article 331, a 429 arrives with an error code saying the organization's monthly spend cap is reached, and no retry-after. The job stops, writes "stopped: spend cap reached at article 331; 69 remaining" to its run log, and exits.
15. Corrections to the earlier version of this page
The earlier page (machine-generated on 27 September 2026 by an open-weight model, per its own frontmatter) has been replaced. Specific changes:
- Removed uncited figures. The page attributed a 37 percent latency improvement and a drop in "peak concurrent retries from 8 000 to 2 100" to "a 2018 study by the Netflix engineering team." No source was given and none was found for this article, so it is dropped. The same applies to "a 23 % reduction in 5xx errors and a 15 % drop in average latency" attributed to Google Cloud Pub/Sub, the claim that a retry burst "can jump from 10 000 rps to 100 000 rps" with latency rising "from an average of 120 ms to over 2 seconds," and the monitoring thresholds presented as norms. The verified simulation result on jitter is Brooker's 2015 AWS post (section 5).
- Removed the bee section. It cited "Research from the University of Zurich (2022)" on foraging intervals growing "by a factor of 1.9." No source was provided, and Apiary's rules exclude unsourced biology claims.
- Fixed the
Retry-Afterparsing sample (section 6): it crashed on the HTTP-date form and defaulted to a one-second retry when the header was absent. - Added the distinction between temporary rate limits and spend or quota caps that share HTTP 429, with provider documentation.
16. A reference policy, in one table
An editorial synthesis of the sources above, for a typical client calling a third-party API. Adjust to the documented behavior of the API you call.
| Setting | Suggested starting point | Why |
|---|---|---|
| Retryable errors | Connection errors, timeouts, 408, 429 (rate limit only), 500, 502, 503, 504, provider overload codes | Documented defaults of AWS, Google Cloud, Anthropic, OpenAI SDKs |
| Never retry automatically | 400, 401, 403, 404 (unless known lag), 422, spend/quota/billing codes | They will not succeed later; providers say so |
| Non-idempotent writes | Retry only with an idempotency key or a prior status check | RFC 9110 §9.2.2 |
| Backoff | Exponential, capped, full jitter | AWS blog and SDK docs |
| Server hints | Use Retry-After (both forms) or a provider retry header as a floor | RFC 9110, provider docs |
| Attempts | About 3 for interactive calls; more only for watched, long-running tools | AWS, Anthropic, Google SRE defaults; gcloud contrast |
| Total time | Bounded by the caller's deadline | Google SRE deadline propagation |
| Layers | One | AWS 243x and Google 64x arithmetic |
| Budget | Stop retrying when retries exceed a small share of traffic | Google SRE 10 percent example; AWS and gRPC token buckets |
| Streams | Do not auto-replay after output was consumed | OpenAI, Anthropic, gRPC docs |
| On stop | Record reason and remaining work | Microsoft Retry pattern logging guidance |
17. What the evidence does and does not show
It shows that backoff without jitter leaves clusters of synchronized retries, and that jitter substantially reduced total work in AWS's simulation (Brooker 2015). It shows that the largest cloud providers now ship jittered backoff, attempt limits and retry budgets as defaults, and document them.
It does not show a universal best set of numbers. The documented defaults range from three attempts to thirty-two, and from millisecond to multi-minute caps, because the right numbers depend on the caller's deadline and the cost of failure. The layering figures (243x, 64x) are illustrations of multiplication, not measurements of any particular system. Google's adaptive-throttling and retry-budget results are reported from Google's own operations; they are experience reports, not controlled studies. And provider behaviors, header names and SDK defaults cited here are dated 26 November 2026; AWS's page itself flags a behavior change in progress.
Related reading on Apiary
- what-goes-wrong-with-uncontrolled-retries
- biggie-idempotency-in-apis
- rate-limit-vs-spending-or-daily-limit
- request-failure-vs-unknown-execution-outcome
- biggie-circuit-breaker-pattern
- guide-make-a-small-automation-retry-without-duplicating-the-work
Sources
Last checked: 2026-11-26.
- Fielding, R., Nottingham, M., Reschke, J. (eds.). "RFC 9110: HTTP Semantics." IETF, June 2022. https://www.rfc-editor.org/rfc/rfc9110 - Retry-After (§10.2.3), 503 (§15.6.4), retry rule for non-idempotent methods (§9.2.2).
- Nottingham, M., Fielding, R. "RFC 6585: Additional HTTP Status Codes." IETF, April 2012. https://www.rfc-editor.org/rfc/rfc6585 - 429 and optional Retry-After (§4).
- Brooker, M. "Timeouts, retries, and backoff with jitter." Amazon Builders' Library. https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/ - retries are selfish, capped backoff, 243x layering example, token bucket since 2016, timeout selection, consistent jitter for scheduled work.
- Brooker, M. "Exponential Backoff And Jitter." AWS Architecture Blog, 4 March 2015, updated May 2023. https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ - simulation of Full, Equal and Decorrelated jitter.
- Amazon Web Services. "Retry behavior." AWS SDKs and Tools Reference Guide. https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html - 2026 opt-in behavior, error classes, backoff formula, max attempts, retry quota parameters, adaptive mode, x-amz-retry-after.
- Featonby, M. "Making retries safe with idempotent APIs." Amazon Builders' Library. https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/ - value of simple retries, idempotency prerequisite.
- Ulrich, M. "Addressing Cascading Failures," ch. 22 in Site Reliability Engineering (Google). https://sre.google/sre-book/addressing-cascading-failures/ - randomized backoff, per-request limits, server-wide retry budget, 64-attempt example, deadline propagation.
- Forero Cuervo, A. "Handling Overload," ch. 21 in Site Reliability Engineering (Google). https://sre.google/sre-book/handling-overload/ - adaptive throttling, three-attempt and 10 percent retry budgets, "overloaded; don't retry."
- Google Cloud. "Retry strategy," Cloud Storage documentation. https://cloud.google.com/storage/docs/retry-strategy - retryable responses, idempotency categories, client library backoff defaults, gcloud 32 retries.
- gRPC Authors. "Retry" guide. https://grpc.io/docs/guides/retry/ - transparent retry, ±20 percent jitter, retry throttling, commit point.
- Microsoft. "Retry pattern." Azure Architecture Center. https://learn.microsoft.com/en-us/azure/architecture/patterns/retry - cancel/retry/delay strategies, context-dependent policy, nested retries, logging.
- Microsoft. "Retry Storm antipattern." Azure Architecture Center. https://learn.microsoft.com/en-us/azure/architecture/antipatterns/retry-storm/ - limits on duration, honoring retry-after, 400 not retryable.
- Anthropic. "Rate limits," Claude Platform documentation. https://platform.claude.com/docs/en/api/rate-limits - retry-after semantics, spend-cap 429 without retry-after, rate-limit headers, ramp limits.
- Anthropic. "Claude API errors," Claude Platform documentation. https://platform.claude.com/docs/en/api/errors - SDK retry defaults, x-should-retry, backoff range, stream errors.
- OpenAI. "Rate limits," API documentation. https://developers.openai.com/api/docs/guides/rate-limits - Retry-After as minimum plus jitter, SDK retries, nested-loop warning, slow_down and ramp guidance, headers, example parser.
- OpenAI. "Error codes," API documentation. https://developers.openai.com/api/docs/guides/error-codes - billing, spend and quota errors not retryable.
- Stripe. "Advanced error handling." https://docs.stripe.com/error-low-level - Stripe-Should-Retry header.
- Leach, B. "Designing robust and predictable APIs with idempotency." Stripe blog, 22 February 2017. https://stripe.com/blog/idempotency - 2^n backoff description, thundering herd.
- Polli, R., Martinez, A., Miller, D. "RateLimit header fields for HTTP." IETF Internet-Draft draft-ietf-httpapi-ratelimit-headers-12, 20 November 2026 (work in progress). https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers - proposed RateLimit-Policy and RateLimit fields.