Learning path: AI System Design: Reliable, Fast and Affordable LLM Apps · Step 1 of 15
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
What you will learn
- Run four checks on every backup model: allowed, fits, user told, rehearsed
- Walk a fallback chain that skips a model on data residency and on context size
- Explain why failing loudly beats sending data to the wrong region
- Rehearse a fallback with a game day and three metrics
Before you start
- What an LLM can and cannot do
- LLM Tokens, Context Windows and Cost
When the main model fails, you switch to a backup. That part is easy to say. The hard part is that the backup has to be allowed to take the request, it has to be able to read the whole request, and it has to be tested before the bad day arrives. So it's plan B, but rehearsed.
Everything in this lesson comes from a small simulation. No model provider was called.
Four checks on plan B
The bad day, and the interview question
A support assistant is handling a refund email, and it calls the main model. Today that model just hangs, and every call times out. So the app switches to the backup, which nobody has ever tested. Worse, that backup runs outside the region this customer allows. (This scenario is for illustration.)
Design a fallback chain for a customer whose data must stay in the EU, and show how you'd test it before the outage.
Think of a play. The lead actor is your main model. The understudy, who has rehearsed the same lines on the same stage, is a tested backup. An understudy walking on for the first time on the night is a backup nobody tried. And the stage manager telling the audience who's playing tonight is you telling the user. An understudy who never rehearsed isn't a plan.
The chain, link by link
Four simulated models, a European customer and a request of 6,000 tokens. Region and size are checked before any call is made:
- primary-eu is down, so it's marked failed.
- backup-us is healthy and big enough, but the region rule stops it. That's the tempting one, and we say no.
- small-eu is in the right region, but 6,000 tokens won't fit, so it's skipped too.
- mid-eu takes it, in 1.3 simulated seconds. The answer is flagged as degraded, so the app can tell the user and you can count how often it happens.
Here is the simulator's own line for this request (simulated, no real API call):
6000 {'served_by': 'mid-eu', 'degraded': True, 'skipped': [('primary-eu', 'failed'), ('backup-us', 'residency'), ('small-eu', 'context')], 'seconds': 1.3}
When nothing is allowed
Now make the request bigger: 10,000 tokens, same outage. Primary has failed, the US model is blocked, and the two EU models are too small. So nothing serves it:
10000 {'served_by': None, 'degraded': True, 'skipped': [('primary-eu', 'failed'), ('backup-us', 'residency'), ('small-eu', 'context'), ('mid-eu', 'context')], 'seconds': 0.9}
That's the right result. Failing loudly beats quietly sending data to the wrong region. So what does the user see? A plain reply with no model at all, one that says we can't answer this right now. That's your last resort. The simulation only reports the failure, so the plain reply is design advice, not something it tested.
The quiet trap: the backup reads less
For illustration, say a refund needs five pieces of evidence: the email, the order, the policy, past refunds and the limit rule. The backup has a smaller context window, which is how much text a model can read at once. Say it has room for three.
If you just cut to fit, two pieces fall away. There's no error. So check the fit before you switch. Too big is just another no.
Rehearse it with a game day
A game day is a planned drill where you break the main model on purpose. Then you check who served each request, whether it stayed in the region, and whether degraded was set. And you measure three things (these are what you'd watch; the lesson has no drill result):
| Metric | What it tells you |
|---|---|
| Fallback rate | How often the backup answers |
| Quality gap | The backup's score against the main model's, on a fixed test set |
| Failover time | From the first failure to the first backup answer |
If you haven't measured it, you don't have it. The fixed test set is the same idea as in Why You Cannot Ship Without an Eval.
Follow-ups and a simple rubric
- Why not fall back to any healthy model? Because healthy doesn't mean allowed, and it may not fit.
- Do you fall back when the model refuses? Usually no. A refusal isn't an outage, so you don't go shopping for a model that says yes.
- What's the last resort? A plain reply with no model, one that says so.
| Level | Sounds like |
|---|---|
| Weak | "We have a backup." |
| Good | An ordered chain, a region rule and a check on the fit |
| Strong | Also flags degraded answers, ends with a plain reply, and rehearses it with a measured game day |
The rubric is a guide for practice, not a guaranteed result. Fallbacks usually sit next to retries: see Retries and Backoff for when to retry the same model first.
Recap
| Idea | What to remember |
|---|---|
| Every link | Allowed for this data, and the request fits |
| 6,000 tokens (simulated) | Served by mid-eu, flagged degraded |
| 10,000 tokens (simulated) | Nobody serves it; fail loudly, plain reply |
| Before the outage | Game day: fallback rate, quality gap, failover time |
Try it yourself
Imagine mid-eu had room for 10,000 tokens. Who serves that big request now, and is it still flagged degraded?
Related course on Udemy
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)Related posts
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.
Caching for AI Apps: Four Layers, What Goes in Each Key, and How a Delete Travels
A support bot's cache can hit 97% of requests and still answer only 52% correctly. Four cache layers, the key each one needs, how a document delete has to travel through all of them, and a 200-request simulation that puts hit rate next to correct answers.