Inference, Serving & Production·Question 43 of 76AdvancedAI-75

Design the reliability layer for calls to an LLM provider: timeouts, retries, circuit breakers, idempotency.

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Timeouts - layered, never one number. A single 120 s timeout is wrong for a streaming call: it can't distinguish "slow but progressing" from "hung." Use: connect timeout (seconds); TTFT timeout (no first token within ~10-20 s → dead request); inter-chunk inactivity timeout (stream silent for ~30 s → hung; beware legitimate pauses during provider-side tool use - heartbeats help); total wall-clock cap per feature. Tune per model class - reasoning models legitimately think for a long time before the first visible token.

Full worked answer with diagram

Timeouts - layered, never one number. A single 120 s timeout is wrong for a streaming call: it can't distinguish "slow but progressing" from "hung." Use: connect timeout (seconds); TTFT timeout (no first token within ~10-20 s → dead request); inter-chunk inactivity timeout (stream silent for ~30 s → hung; beware legitimate pauses during provider-side tool use - heartbeats help); total wall-clock cap per feature. Tune per model class - reasoning models legitimately think for a long time before the first visible token.

Retries - bounded and honest. Retry 429/5xx/network failures with exponential backoff + full jitter, honoring Retry-After; never retry 4xx validation errors. Cap at 2-3 attempts with an overall latency budget, and a global retry budget (if >~10% of traffic is retrying, you're amplifying an outage - shed instead). Mid-stream failure is the nasty case: a retry regenerates from scratch, possibly producing different text - the UI must replace, not append, and anything already acted on downstream must be handled (see idempotency). Hedged requests (fire a second call at ~P95, take the winner) buy tail latency for money - use only on idempotent, high-value paths.

Circuit breakers - per provider × model. Track failure rate over a sliding window; open the breaker on sustained failure (fail fast, stop feeding a dying dependency), pass limited probes half-open, close on recovery. On open: route to the fallback chain - same-family smaller model, or another provider - pre-validated with evals, because prompts don't transfer 1:1 and a silent quality collapse is worse than an error page. Bulkhead traffic classes so background jobs can't exhaust connections/quota needed by interactive traffic.

Idempotency. The LLM call itself is stateless - safe to retry, at worst you pay twice. The danger is side effects around it: a retried agent step re-executing a tool (double email, double write). Assign idempotency keys to side-effectful operations, dedupe at the tool layer, and make pipeline steps replay-safe (retried batch item overwrites by custom_id, not appends). State machines, not vibes: each request has an ID and a durable status.

Worth sketching. The three breaker states plus the half-open probe are the part people describe vaguely, and the sketch forces the transitions to be exact.

flowchart LR
    C["Closed: calls pass through"] -->|"failure rate over the window"| O["Open: fail fast,<br/>stop feeding a dying dependency"]
    O -->|"cool-down elapsed"| H["Half-open: a few probes only"]
    H -->|"probes succeed"| C
    H -->|"probe fails"| O
    O --> F["Fallback chain, eval-gated per feature,<br/>not merely API-compatible"]

What a good answer covers

  • Timeouts - layered, never one number
  • A single 120 s timeout is wrong for a streaming call
  • Tune per model class - reasoning models legitimately think for a long time before the first visible token
  • Retry 429/5xx/network failures with exponential backoff + full jitter, honoring Retry-After; never retry…
  • Cap at 2-3 attempts with an overall latency budget, and a global retry budget (if >~10% of traffic is…

Key terms: TTFT timeout · inter-chunk inactivity timeout · Retries - bounded and honest · Idempotency · side effects around it

Interviewer follow-ups to expect

  1. A stream dies at token 400 of a 600-token answer the user is reading - walk through exactly what happens. Why must fallback models be eval-gated rather than just API-compatible?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep