Question presented to candidate: "Our product makes a few hundred thousand model calls a day, and every week or so the provider throws 429s or 529s, or one region just times out, and our users see a spinner and then an error. Walk me through how you would wrap our LLM calls so that rate limits, transient failures and a full provider outage do not become user-facing outages."
What a strong answer should cover:
- Classify failures first: retry only transient ones (429, 408, 409, 5xx and overloaded, timeouts, dropped connections); never retry a 400, 401, 403 or a spend-cap 429, and fail those fast
- Exponential backoff with jitter (full jitter spreads retries; no jitter makes every client retry in the same instant), honour
retry-afterwhen the server sends it, cap the attempts and keep one overall deadline per user request - Stay under the limit instead of bouncing off it: a client-side token bucket or queue sized to your RPM and tokens-per-minute limits, priority for interactive traffic, batch or defer the rest
- A circuit breaker per provider or region (closed, open, half-open) so a dead tier is skipped instantly instead of costing every request its full retry budget
- A fallback chain ordered by how similar the behaviour is (same model in another region, then a sibling model, then another provider) with every fallback in the eval suite, plus an explicit degraded mode in the product
- Idempotency and streaming details: do not blindly retry calls that triggered side effects (tool calls), and treat a stalled or mid-stream error as a failure to handle, not a success
Clarifying questions expected:
- What is the latency budget for a user request, and is the traffic interactive, background, or both?
- Are we on one provider and one region today, and are fallback models already evaluated for this feature?
- Do any of these calls trigger side effects (tool calls, writes) that must not run twice?
Code / implementation expected: Optional โ a retry wrapper with error classification, jittered backoff, retry-after handling and a fallback list is enough; a circuit breaker is a strong extra.