Wrap Model Calls With Backoff and Schema-Repair Retries
Last updated: November 29, 2026
Quick Overview
Write a helper that calls an LLM, retries transient provider errors with capped exponential backoff and jitter, and on schema-invalid output re-prompts the model with the validation error instead of sleeping, giving up after a fixed number of attempts.
Ode
November 29, 20260
0
0 solved
Write a helper that calls an LLM, retries transient provider errors with capped exponential backoff and jitter, and on schema-invalid output re-prompts the model with the validation error instead of sleeping, giving up after a fixed number of attempts.
Almost every production system Ode ships for a client sits behind a call like this, and flaky retry logic is a common cause of cost blowups and silent data loss. The interviewer is looking for a clear separation between infrastructure failures and model output failures, and for testable code (injected sleep and randomness).
What the Interviewer Expects
- Distinguish retryable transport errors (429, 5xx, timeouts) from bad output
- Use full-jitter exponential backoff with a cap
- Feed the validation error back to the model on schema failures, without sleeping
- Bound total attempts and raise with the last cause attached
- Inject sleep and random sources so the logic is unit-testable
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
- Which errors must never be retried, and why?
- How would you make retries safe when the call triggers a side effect, like creating a ticket?
- How would you add a total deadline rather than an attempt count?
- When would you fall back to a different model, and how would you log that?
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
call(feedback) sends the prompt (plus optional repair feedback) and returns raw text or raises RetryableError. validate(raw) returns a parsed object or raises SchemaError. The helper returns t...
High-Level Design
One loop with two failure branches. Transport failure: sleep random() * min(cap, base * 2^attempt) (full jitter spreads synchronized clients) and resend the same prompt. Output failure: the provider...