HTTP 429 and Retry-After: Schedule the Next Attempt Without a Retry Storm
For HTTP 429, honor the service's documented limit and any valid Retry-After header. Space out permitted retries and stop when the request's retry budget is exhausted. Retrying immediately can add load at the worst time.
Interpret the header before sleeping
Retry-After can be a delay in seconds or an HTTP date. In a synthetic response of Retry-After: 120, the server asks for a two-minute delay. For an absolute HTTP date, use a suitable parser and compare with the current UTC time. If a valid delay exceeds the time available to your task, defer it or report the rate limit.
Bound replay and concurrency
When the service permits retrying and provides no usable wait, follow its documented backoff guidance and add jitter where appropriate so clients do not all retry together. Cap the attempt count and total wait. For a non-idempotent operation, verify the API's replay behavior before sending it again.
Test with a stub and count actual attempts
Return one synthetic 429 and then a success from a local stub. Verify that a valid header defers the second request and that exhausted attempts surface an explicit error. Add invalid and absent header cases. In production diagnostics, compare attempt count and concurrency with the service's permitted usage rather than trying to avoid its controls.
댓글
댓글 쓰기
안녕하세요 :)