Resilience: multi-provider failover & degradation

In one sentence

LLM providers fail loudly (outages, 429/529) and quietly (latency spikes, quality regressions). Time out fast, retry with backoff, trip circuit breakers, fail over to an evaluated backup, then degrade gracefully.

Analogy: A hospital's power: grid first, then a generator that is tested monthly, then battery for critical machines, then flashlights. Each step does less, but the lights never go fully out.

Each rung trades quality for availability. Test every rung regularly, or it fails the day you need it.

How it works

  • Not all failures are loud: latency spikes and quality regressions can return HTTP 200 with no error.
  • Set timeouts on TTFT and total time, and retry only transient errors, within a retry budget.
  • A circuit breaker per provider and region stops traffic after N failures, then probes for recovery.
  • The backup model needs its own prompt and evals: a prompt tuned for one model can break on another.
  • Last, degrade step by step: smaller model, cached answer, plain search results, then a human.

Check yourself

Answer to mark it learned; your answers aren't scored.

Your primary LLM provider goes down. The breaker opens and traffic fails over to Provider B as designed, but the downstream parser starts crashing: B's answers break your JSON schema. What should have prevented this?

Go deeper

Full explanation

You inherit the reliability of every provider you call, and LLM APIs fail in more ways than most dependencies:

  • Hard failures: regional or global outages, 5xx errors.
  • Overload: 429 rate limits, Anthropic's 529 overloaded, no capacity in one region.
  • Latency spikes: TTFT jumps from 1 s to 20 s with no error.
  • Silent quality regressions: a provider bug or model update degrades answers while returning HTTP 200.

The patterns, in the order a request meets them (Retries, backoff & circuit breakers):

  1. Timeouts on TTFT and total time, not just on connect.
  2. Retries for transient errors only, with backoff, jitter and a retry budget.
  3. Circuit breaker per provider and region: after N failures, stop sending traffic, then probe.
  4. Fallback to another region or provider, usually in the LLM gateway. The backup needs its own prompt and evals: a prompt tuned for one model can lose quality or break the JSON schema on another.
  5. Hedged requests: if the first call is slower than ~p95, send a second and keep the winner.
  6. Degradation ladder: smaller model → cached answer → plain search results → human.

For critical traffic, buy reserved capacity (Azure OpenAI PTUs, Bedrock or Vertex AI provisioned throughput, priority tiers) and route across regions. Set SLIs, SLOs & error budgets on success rate, TTFT and an online quality score.

Code Circuit breakers over a fallback ladder
pythonCircuit breakers over a fallback ladder
import time

class Breaker:
    def __init__(self, threshold: int = 5, cooldown_s: float = 30):
        self.fails, self.opened_at = 0, None
        self.threshold, self.cooldown = threshold, cooldown_s

    def allow(self) -> bool:        # after the cooldown, let traffic probe again
        return self.opened_at is None or time.monotonic() - self.opened_at > self.cooldown

    def record(self, ok: bool) -> None:
        self.fails = 0 if ok else self.fails + 1
        if ok:
            self.opened_at = None
        elif self.fails >= self.threshold:
            self.opened_at = time.monotonic()

# Each rung has its own prompt, evaluated on the golden set every week
LADDER = [("primary", call_primary, 20), ("backup", call_backup, 20), ("small", call_small, 8)]
breakers = {name: Breaker() for name, _, _ in LADDER}

def answer(msg: str) -> str:
    for name, call, timeout_s in LADDER:
        if not breakers[name].allow():
            continue                                  # fail fast, don't pile on
        try:
            out = call(msg, timeout=timeout_s)        # SDK retries 429/5xx with backoff
            breakers[name].record(True)
            metrics.incr("llm.served_by", tags={"rung": name})  # alert on fallback share
            return out
        except (TimeoutError, RateLimited, Overloaded, ServerError):
            breakers[name].record(False)
    return cached_answer(msg) or search_results(msg) or handoff_to_human(msg)
Real example

A support assistant runs on Provider A with a 99.9% SLO for successful answers. During a 3-hour regional overload, 529s jump to 30%. The breaker opens after 5 consecutive failures; the gateway first moves traffic to the same model in a second region, then to Provider B when that region saturates. Provider B has its own prompt, re-run weekly on the golden set (0.86 vs 0.89 for the primary). Users get slightly shorter answers, the SLO holds, and on-call gets one alert: fallback share above 20%.

Trade-offs +3 · −3

+ You gain

  • A provider outage becomes a small quality dip instead of a down product.
  • Timeouts and hedging cut tail latency, which users feel more than the mean.
  • A second provider also gives pricing leverage and a ready migration path.

− You pay

  • Every fallback is another prompt, eval suite and contract to maintain.
  • Cross-provider failover can break data-residency or zero-retention commitments.
  • Retries and hedges add load and cost; done naively, they amplify an outage.

Use it when

Customer-facing or revenue-critical LLM features whose availability SLO is higher than one provider delivers, or where a multi-minute outage makes headlines.

Avoid it when

Internal tools and batch jobs that can wait: a queue plus retries beats a second provider you must keep evaluated.

Numbers to know 5
  • Serial availability: a 99.9% app on a 99.5% model API ≈ 99.4%. An independent fallback lifts the model tier to ~99.997% (independence is optimistic).
  • The Tail at Scale (Google): a hedged request after 10 ms cut p99.9 latency from 1,800 ms to 74 ms with only 2% more requests.
  • Google SRE: at most 3 attempts per request; keep retries under ~10% of a client's traffic.
  • Anthropic postmortem (Sep 2025): a routing bug degraded up to 16% of Sonnet 4 requests in the worst hour, with no errors returned.
  • Anthropic returns 429 for rate limits and 529 when overloaded; retry both with backoff.
Common pitfalls 4
  • An untested fallback: the backup prompt breaks the output schema on the day the primary goes down.
  • Retrying in every layer (SDK, gateway, app) multiplies load on an already overloaded provider.
  • Alerting only on HTTP errors: latency spikes and silent quality drops need TTFT SLOs and online evals.
  • Failing over to a provider or region your data-processing agreement doesn't cover.
Interview questions 3

Answer out loud first, then reveal.

Your main LLM provider is down for two hours. What happens in your system?Show answer

The breaker for that provider opens after a handful of failures, so we stop burning time on timeouts. If the outage is regional, the gateway moves to the same model in another region; otherwise to a second provider with its own tuned prompt, which we evaluate weekly against the golden set. If both are saturated, we drop to a smaller model with fewer features, then cached answers or search results, and finally a human handoff. Users see a banner, not an error page. The price is maintaining that second prompt and eval suite.

How would you detect a silent quality regression from a provider?Show answer

Error rates and latency won't show it, so I run online evals: sampled production traces scored by deterministic checks like schema validity and citation coverage plus an LLM judge, and the user-feedback rate, each alerting on a drop versus the trailing week. I pin model snapshots where possible and run a small canary golden set every hour against the live endpoint. Anthropic's 2025 postmortem is the textbook case: infrastructure bugs degraded answers while requests returned 200.

When would you use hedged requests, and what's the catch?Show answer

When tail latency matters more than cost, like a voice agent where a 10-second TTFT means a hang-up. I send the second request only after the first passes roughly the p95, so extra load stays near 5%. The catch with LLMs is that both calls bill tokens, so I cancel the loser as soon as the winner streams its first token, and I never hedge calls with side effects, like tool actions.