Spot the flaws in this three provider fallback chain
Click any words you think contain an error. Click again to unmark.
The chain wastes cost on errors that retry cannot fix, stacks timeouts past any user patience, ignores per-provider request adaptation, double-fires side effects, and lacks circuit breakers.
Picture a relay race where the second runner cannot hear that the first runner fell. The whole team waits sixty seconds at the first baton drop before passing it. Then the second runner trips on a hurdle that only existed on their lane. Then the third runner sets off, and along the way some volunteers run out and hand prizes to spectators every time a runner passes, so by the end three sets of prizes have gone out for one race. That is what this fallback chain does. It waits, it does not adapt, and it re-fires side effects. A real chain skips known-down providers, bounds the user's total wait, reshapes the request per provider, and never re-executes work that already happened.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Multi-provider fallback is one of those patterns that looks trivial in a sprint plan and becomes a quiet liability in production. The trivial version is the try/except wrapper this v1 design embodies. It catches the right exception and retries on the next provider. It also wastes spend, blows the latency SLO, corrupts side-effecting tool calls, and tortures users during partial outages.
The five flaws in this snippet are not arbitrary. They map to five standard reliability patterns: error classification, latency budgeting, per-provider request translation, idempotency, and circuit breaking. Each is its own small subsystem. Together they turn the chain from a liability into something a senior engineer can defend in an incident review.
This deep dive walks each of the five and shows what a defensible chain looks like end to end.
Error taxonomy first, retry policy second
The hot path of any fallback chain is error classification. Retry policy without classification is just amplification of the wrong things.
Provider errors fall into three buckets. Deterministic errors are reproducible across providers given the same input: 400s for malformed requests, 401/403 for misconfigured auth, content-policy blocks for prompts that any major provider will reject, schema validation failures from structured-output mode. Retryable transient errors are correlated with provider state, not request state: 429 rate limits, 500/502/503/504 server errors, network timeouts that did not see the request completed. Ambiguous errors are the gray zone: timeouts mid-stream where some tokens may have been generated, partial tool calls.
The rule is simple: only retryable transient errors fall through to the next provider. Deterministic errors return immediately to the caller with the original status, since retrying cannot fix them and only burns money and time. Ambiguous errors need product-level policy: prefer to surface them to the caller rather than risk side-effect duplication.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- LiteLLM and OpenRouter implement provider fallback with error classification and per-provider timeouts as first-class features
- Vercel AI Gateway and AWS Bedrock cross-region routing combine circuit breakers with health probes to skip degraded endpoints
What an interviewer would ask next. Try answering before peeking at the approach.
QWhen would you prefer hedged requests over sequential failover?
Hedging fires to two providers concurrently after a short head start delay and takes the first to return. It improves p99 latency at the cost of duplicate spend. Pick it when latency tail matters more than cost, typically for interactive surfaces with high cost per millisecond.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Treating every non-200 as retryable feels safe but means a 400 from a malformed prompt or a content-policy block costs three full provider round trips, three bills, and three times the user wait.
60 second bullets to scan on the way to the call.
How to classify provider errors into deterministic, retryable, and ambiguous
Why a user-facing latency budget beats stacked per-provider timeouts
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.