# What Is Multi-Provider Fallback?

> How to keep an AI app working when one model provider is overloaded, what breaks when you switch, and how to build it safely, explained simply for your AI interview.

**In short:** Multi-provider fallback means keeping a second model provider ready and sending requests there when the main one fails or is overloaded. Retry the main one with waits first, and move to a backup only after it has passed your own tests and keeps data where your rules need it.

AI and LLM interview question Q343, Inference, performance and cost. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/multi-provider-fallback

## Say it in 30 seconds

Multi-provider fallback means I keep a second model provider ready. First I retry the main one with short waits, because many errors clear fast. If it's still overloaded, a circuit breaker stops calling it for a while and the backup answers. A backup can differ from the main model in ways that matter. Answers, error codes, data location and cache hits can all differ, so it has to pass the same tests before it takes live traffic.

## Say it in 2 minutes

A model provider can be slow, full or down. Anthropic's docs say a 529 error can happen when traffic across all users is high, and OpenAI returns a 503 when a model is overloaded. If my app depends on one provider, my users wait or see errors. So I keep a second provider ready and send work there when the first one fails.

The order matters. I retry the main provider a couple of times with waits, and I honour its Retry-After header. Retries don't fix a spend cap, so a billing limit sends an alert to a person, not a switch. After repeated overloads, a circuit breaker stops calling the main provider for a while, so each chat doesn't wait on a dead service. Each chat also gets one overall time budget, so the total wait stays bounded.

Switching is the hard part. Answers differ between models, so the backup runs the same evals first. Error codes differ too, so I map each provider's errors to one rule. A backup in another region can break data residency rules, and a new provider needs its own contract. Tool calls that already sent an email or moved money must not run twice.

So my answer is: retry, then a breaker, then a tested backup, then a queue or a person. I log which provider answered each chat, so I can see when the backup is doing the work.

## What is multi-provider fallback, in plain words?

Many apps call one AI model company, which is called a provider. Multi-provider fallback means you also set up a second provider, and send the work there when the first one fails, is overloaded or is too slow.

Think of a bank's card terminal. If one card network is down, the till does not close. It tries another route, and the customer still pays. The app does the same thing with a second model.

Here is a realistic case with made-up numbers. A mid-size bank runs a support assistant for about 40,000 chats a day. At 10:05 on the last working day of the month, the main model starts returning overload errors. With no backup, every chat fails at the peak. With a tested backup, most chats still get an answer, and the bank checks the replies that came from the backup.

- **Provider:** The company or cloud that runs a model and sells access to it.
- **Fallback:** The second option the app uses when the first one fails.
- **Overload error:** A reply saying the model is too busy. Anthropic uses 529, OpenAI uses 503.
- **Circuit breaker:** A switch that stops calls to a failing service for a while, instead of hitting it every time.
- **Data residency:** A rule that customer data must stay in a set country or region.

## Why not just retry the same provider?

Retrying is the first move, because many errors clear within seconds. But an overload is shared across many customers of the same provider, so a retry against that provider can hit the same wall. Anthropic's own docs describe its 529 error as a sign of high traffic, and AWS says availability targets need bounded retries and a fallback in your application.

> "To meet an availability target, add bounded retries and multi-Region or multi-model fallback in your application" (AWS)
>
> "A 529 error can occur when the API experiences high traffic across all users" (Anthropic)

So the rule of thumb is: retry a few times with waits, then move on. Retries don't fix a billing limit. Anthropic says a spend-cap 429 has no retry-after header and keeps failing until access resumes, so the right step there is to alert a person.

> **Tip:** Asked what triggers a fallback? Name overload errors (529 or 503), timeouts, and a 429 that outlasts a short retry. A bad request (400) normally should not fail over, because a backup gets the same bad input. If the 400 says a feature is unsupported, a backup that has the feature may succeed.

## How does one chat move through a fallback?

*Diagram, One chat through a fallback: A chat tries the main provider twice, with a wait between tries. If both tries fail, that chat goes to the backup, and after four failed main calls in a row the breaker skips the main provider for later chats. Every reply is logged with the provider that sent it.*
1. The question goes to the main provider first.
2. A healthy main provider sends the reply back.
3. Two failed tries in a row: the breaker counts it.
4. Breaker open: the main provider is skipped for now.
5. The main provider's reply goes out and is logged.
6. The backup's reply goes out and is logged too.

A breaker stops the app paying for the same failure again and again. Azure's circuit breaker pattern says a breaker blocks access to a failing service after failures reach a threshold, instead of repeatedly retrying an operation that is likely to fail. Once failures pass the threshold within a set time window, calls stop and a timer starts.

When the timer ends, the breaker lets a limited number of trial calls through. Those calls check whether the service has recovered. If they succeed, the breaker closes and traffic goes back to the main provider. The Half-Open state also helps stop a recovering service from being flooded with requests.

## What breaks when you switch providers?

- **Answers: Same input, different output.** Models can give different output for the same input, so a backup needs its own tests before it takes live chats.
- **Errors: Each provider names its errors.** Anthropic sends 529 with overloaded_error. OpenAI sends 503 with server_is_overloaded. Map both to one rule in your code.
- **Data: Location and contracts.** A backup in another region can break residency rules. A new provider also needs its own contract and security review.

A compatibility layer (a translator that lets code written for OpenAI's SDK, the official code library, call Claude) still needs its own testing before you rely on it. Anthropic's OpenAI SDK compatibility page says the strict parameter for function calling is ignored, so tool output is not guaranteed to match your schema. The same page says the layer is not considered production-ready for most use cases.

The same model can also arrive through a cloud. Anthropic's Bedrock page says calling Claude through Bedrock slightly differs from calling the Claude API directly, and that lifecycle dates on partner platforms can differ from the Claude API schedule.

Caches don't carry over. OpenAI says a later request with the same prefix can reuse saved state, and it looks for a matching prefix already cached on the machine. So a cache hit needs the same prefix, and a new provider starts with an empty cache. The first calls after a switch do the full work again.

> **Tip:** Agents that change things outside the app need extra care. If the main provider already sent the email or moved the money before it failed, a retry on the backup would do it twice. Put the action behind a check, or make it safe to repeat.

## How do you build a fallback safely?

1. **Set one time budget per chat:** Give each chat an overall deadline, for example 15 seconds. Every try uses part of it, and the chat stops when the deadline ends.
2. **Retry first, with waits:** Retry the same provider a couple of times, honour its Retry-After wait (the wait time the provider sends back), and cap the number of tries.
3. **Let a breaker decide:** After repeated overloads, stop calling the main provider for a while, then let a few trial calls through.
4. **Keep the backup inside the rules:** Check data location and contracts first. Pick a route that keeps data where your rules say, such as a geographic route when residency applies.
5. **Test the backup like the main one:** Run the same evals (a fixed set of test questions with known good answers) on the backup, and log which provider answered each chat.
6. **Have a last step:** If every provider fails, queue the chat or hand it to a person, and tell the customer what happens next.

Here is a worked example with made-up numbers. The bank gives each chat 15 seconds. The main model gets two tries, each with a 4-second timeout and a 1-second wait between them, which uses 9 seconds. The backup gets the 6 seconds left. If it fails too, the chat is queued with a message saying a person will reply. The app never waits past its budget, even though it tried two providers.

A connection that drops while an answer is arriving word by word (a stream) is a separate case. Anthropic's errors page says the SDK doesn't retry an error in a stream, so the app must decide whether to show the partial reply or start again on the backup.

Here it is in plain Python, with no real model. The main provider is down for its first four calls, and a breaker stops calling it after four failures in a row.

```python
# Made-up support assistant: the main model is overloaded for its first 4 calls.
FAILOVER = {429, 503, 529}  # overload or rate limit: retry, then move on. A spend-cap 429 also lands here, so a real app reads the error code and alerts a person instead.
calls = {"main": 0, "backup": 0}
state = {"main_failures": 0}  # breaker: failed main calls in a row. Shortcut: never resets here. A real breaker waits, then lets a few trial calls through.

def call(provider):
    calls[provider] += 1  # made-up reply, no network
    return 529 if provider == "main" and calls["main"] <= 4 else 200

def answer(chat):
    # Breaker open after 4 failures in a row: skip the main provider.
    order = ["backup"] if state["main_failures"] >= 4 else ["main", "backup"]
    for provider in order:
        for attempt in range(2):  # short retry on the same provider
            status = call(provider)
            print(f"{chat}: {provider} try {attempt + 1} -> {status}")
            if provider == "main":
                state["main_failures"] = 0 if status == 200 else state["main_failures"] + 1
            if status == 200:
                return f"{chat}: answered by {provider}"
            if status not in FAILOVER:
                return f"{chat}: stopped, a backup won't help"
    return f"{chat}: all providers failed, queued for a person"

print(answer("chat 1"))
print(answer("chat 2"))
print(answer("chat 3"))
print(f"main calls made: {calls['main']}")
```

Output:

```text
chat 1: main try 1 -> 529
chat 1: main try 2 -> 529
chat 1: backup try 1 -> 200
chat 1: answered by backup
chat 2: main try 1 -> 529
chat 2: main try 2 -> 529
chat 2: backup try 1 -> 200
chat 2: answered by backup
chat 3: backup try 1 -> 200
chat 3: answered by backup
main calls made: 4
```

The code stops calling a broken provider, and it never sends a bad request to a backup. The state of the breaker is kept in one place, so a real version would move it into shared storage.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a second provider takes over when the first fails or is overloaded.
- [ ] What triggers it: overload errors, timeouts and a 429 that outlasts a short retry, not a bad request.
- [ ] The order: retry with waits, then a breaker, then a tested backup, then a queue or a person.
- [ ] What breaks on a switch: answers, error codes, data location, cache hits and side effects.
- [ ] A time budget per chat, so the wait stays bounded.
- [ ] An honest limit: a backup nobody has tested gives no protection.

**Common traps**

- Trap: "Switch to the backup at the first error." Better: Retry first with waits. A first error is often a blip, and a fast switch can push the whole load onto a backup that may not have room for it.
- Trap: "A backup is just the same prompt sent elsewhere." Better: Same prompt, different model: answers, error codes and tool output can differ, so the backup needs its own tests.
- Trap: "A fallback gets around a spend cap." Better: A spend cap is a billing limit. Retrying won't restore access, so alert a person. Switching providers to dodge a limit fixes nothing.

## Can you spot the risk?

**Spot the risk:** Which backup setup is risky?

A. A backup in the same EU region, with the same eval set run before go-live
B. A backup in any region with the lowest price, sending EU customer chats there
C. Two tries on the main model, then a backup, all inside a 15-second budget
D. Each chat logged with the provider that answered it

**Answer:** B. Sending EU customer chats to any region can break a residency rule. AWS advises a geographic route when residency rules apply, so the backup has to stay inside the allowed zone.

**Quick check:** The main model returns 400 because one request field is invalid. What should the app do?

A. Switch to the backup, which will probably accept it
B. Retry the main model five times with waits
C. Fix the request and alert a developer, since a backup gets the same bad input
D. Lower the temperature and try again

**Answer:** C. A 400 means the request itself is wrong. Retries and a backup both receive the same bad input, so the fix belongs in the code.

## Can you answer these from memory?

**Flash cards**

- **What is multi-provider fallback?** A second model provider takes the work when the first fails or is overloaded.
- **Which errors trigger a failover?** Overload errors (529 or 503), timeouts, and a 429 that outlasts a short retry.
- **What is a circuit breaker?** A switch that stops calls to a failing service for a while, then lets a few trial calls through.
- **Why not just retry?** An overload is shared, so retries can keep hitting the same wall.
- **What breaks on a switch?** Answers, error codes, data location, cache hits and actions that must not run twice.
- **Does a 400 fail over?** Usually no. The backup gets the same bad request, so fix the request first.

## Likely follow-up questions

- Q330 How do you handle rate limits and 429 errors? https://designervenkat.online/interview/ai/how-do-you-handle-rate-limits-and-429-errors
- Q337 Timeouts, retries and backoff? https://designervenkat.online/interview/ai/timeouts-retries-and-backoff
- Q334 How do you cut cost on a cloud-hosted LLM workload? https://designervenkat.online/interview/ai/how-do-you-cut-cost-on-a-cloud-hosted-llm-workload
- Q344 What is a p95/p99 latency budget? https://designervenkat.online/interview/ai/what-is-a-p95-p99-latency-budget
- Q347 Design a customer-support chatbot. https://designervenkat.online/interview/ai/design-a-customer-support-chatbot
