LearnQuestion bank

Your product depends on an external LLM API that sometimes returns 429s and overload errors and occasionally stalls mid-stream. Design the client-side reliability layer.

Applied LLMTechnicalMedium

Theme reported publicly: ElevenLabs, OpenAI

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Classify errors and retry only transient ones; honour Retry-After; backoff with jitter; bounded retry budgets.
  • Set connect, TTFT and inter-chunk timeouts; cancel stalled streams and never treat partial output as success.
  • Enforce client-side token buckets per model/provider/region and prioritize interactive traffic over batch.
  • Use compatible fallbacks, circuit breakers, and graceful degradation such as cached answers or human handoff.
  • Make side-effecting tool calls idempotent and instrument retries, latency, TTFT, gaps, fallbacks and breaker state.

In full

I would put a reliability wrapper around the LLM client rather than scattering retry logic through product code. It classifies failures first: 429s, overload, 5xx and timeouts are retryable, while validation, auth and schema errors are not; retries use exponential backoff with jitter, respect Retry-After when present, and are capped by a retry budget so a bad dependency cannot amplify load. The wrapper also enforces connect, time-to-first-token and inter-chunk-gap timeouts, cancels stalled streams, and marks partial output as incomplete rather than committing it or triggering side effects. Traffic is shaped with client-side token buckets per model/provider/region and a priority queue so interactive requests are not starved by batch work. For resilience, it falls back to compatible models/regions/providers with prompts that are known to be equivalent, trips circuit breakers per dependency, and degrades gracefully to a cached answer, a clearly labelled partial result, or human handoff. Side-effecting tool calls carry idempotency keys and dedupe so retries do not double-execute, and every path emits traces and metrics for latency, TTFT, chunk gaps, 429s, retries, budget exhaustion, fallbacks and breaker state.

Corrected by an independent AI reviewer.

What a strong answer covers

  • Exponential backoff with jitter for retryable errors; honour retry-after; never retry validation errors; retry budgets
  • Timeouts for connect, TTFT and inter-chunk gaps; strategy for partial streams
  • Client-side token-bucket limits per model; priority queues
  • Fallbacks: other region/provider/model with compatible prompts; circuit breakers; graceful degradation (cached answer, human handoff)
  • Idempotency for side-effecting tool calls; observability

Common mistakes

  • Unbounded retries causing a thundering herd
  • treating every error as retryable