Client Retry Policy With Exponential Backoff, Jitter, and Retry-After
Last updated: November 29, 2026
Quick Overview
Write the retry wrapper an API client uses when calling a model endpoint: retry connection errors, timeouts, 429s, and 5xx responses with capped exponential backoff and full jitter, honor the server's Retry-After header, and stop at a total deadline. Do not retry client errors like 400 or 401.
OpenAI
November 29, 20260
0
0 solved
Write the retry wrapper an API client uses when calling a model endpoint: retry connection errors, timeouts, 429s, and 5xx responses with capped exponential backoff and full jitter, honor the server's Retry-After header, and stop at a total deadline. Do not retry client errors like 400 or 401.
Every OpenAI SDK has to handle rate limits and transient overload gracefully, and a bad retry policy can turn a brief outage into a self-inflicted traffic storm. The interviewer wants to see you separate retryable from non-retryable failures and understand why jitter matters.
What the Interviewer Expects
- Classifies status codes into retryable and not retryable
- Uses capped exponential backoff with full jitter
- Respects Retry-After as a minimum delay
- Bounds both attempts and total elapsed time
- Injects sleep, RNG, and clock so it can be tested
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- When is it unsafe to retry a POST, and how do idempotency keys help?
- How would a retry budget across the whole client prevent retry storms?
- How should streaming responses that fail midway be retried?
- What is the difference between full jitter and equal jitter?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Retry on network errors, 408, 409, 429, and 500 to 504. Raise immediately on other 4xx. At most max_attempts tries and deadline seconds total. Delay never shorter than Retry-After....
High-Level Design
Delay for attempt a is uniform(0, min(cap, base * 2^a)). Exponential growth backs off quickly from an overloaded service; the cap keeps waits sane; full jitter spreads synchronized clients so they...