Skip to content
Goal: Deep understanding✓ Sources verified 2026-11-24FallbackCircuit BreakerRate Limit

Fallbacks, Circuit Breakers and Rate Limiting ​

Core concepts ​

TechniqueWhat it solves
FallbackWhen the main path is unavailable, keep serving with something "a bit worse but working"
Circuit breakerWhen a downstream keeps failing, fail fast and stop calling it, giving it time to recover
Rate limitingControls the traffic entering the system or hitting downstreams, protecting you and your provider quota
BulkheadSeparate concurrency pools per customer / task type, so one problem doesn't take everything down

How it works ​

The fallback ladder for LLM apps ​

① Retry (transient errors)
② Switch model / provider (main model overloaded or down)
③ Lower the bar (shorter context, simpler prompt, skip non-essential steps)
④ Rules / cache as a safety net (regex extraction, results from identical past documents)
⑤ Hand over to a human (see "Human takeover")

At every level, record the reason for the fallback and mark the result as "generated by the backup model" to support tracing and later spot checks.

The three states of a circuit breaker (the pattern as described by Martin Fowler) ​

Closed (normal, counts failures) ──failure rate over threshold──→ Open (fail immediately, don't call downstream)
   ↑                                                                 │ cooldown elapsed
   └──── probe succeeds ──── Half-Open (let a few probe requests through) ←┘
                                └── probe fails → back to Open

Parameters: measurement window, failure rate threshold, minimum number of requests, cooldown, number of probe requests allowed in half-open.

Rate-limiting algorithms ​

AlgorithmCharacteristics
Fixed windowSimple; can allow a 2× burst at window boundaries
Sliding windowSmoother, slightly more complex to implement
Token bucketAllows some burst while keeping the long-run rate under control (most common)
Leaky bucketConstant output rate

LLM providers usually limit both "requests per minute" and "tokens per minute", so client-side rate limiting must account for both.

In practice: model fallback with a circuit breaker ​

python
import time

class Breaker:
    def __init__(self, threshold=5, cooldown=30):
        self.fail, self.threshold, self.cooldown, self.opened_at = 0, threshold, cooldown, None
    def allow(self):
        if self.opened_at is None:
            return True
        return time.monotonic() - self.opened_at > self.cooldown     # after cooldown, go half-open and let a probe through
    def record(self, ok: bool):
        if ok:
            self.fail, self.opened_at = 0, None
        else:
            self.fail += 1
            if self.fail >= self.threshold:
                self.opened_at = time.monotonic()

ROUTES = [("primary", "model-a"), ("backup", "model-b")]   # model names live in config
breakers = {name: Breaker() for name, _ in ROUTES}

async def generate(req):
    errors = []
    for name, model in ROUTES:
        if not breakers[name].allow():
            errors.append(f"{name}: circuit open"); continue
        try:
            res = await call_llm(req, model=model)
            breakers[name].record(True)
            return res.model_copy(update={"fallback_from": ROUTES[0][1] if name != "primary" else None})
        except RetryableExhausted as e:
            breakers[name].record(False); errors.append(f"{name}: {e}")
    raise NeedHumanReview("All models unavailable: " + "; ".join(errors))

Common pitfalls ​

  1. A backup model that was never evaluated: accuracy drops sharply after switching and nobody knows. Run the eval set on the backup model too.
  2. Prompts not adapted for the backup model: different models respond differently to the same prompt. Maintain a separate prompt version for the backup model if needed.
  3. No alert after falling back: the system stays degraded for a long time without anyone noticing.
  4. Circuit breakers counted per instance: in a multi-instance deployment each keeps its own count. Share state via Redis if needed.

Common interview questions ​

  1. What fallback strategies does your LLM app have, and in what order?
  2. What states does a circuit breaker have? How do you set its parameters?
  3. What's the difference between a token bucket and a leaky bucket?
  4. When the main model is down and you switch to the backup, how do you guarantee result quality?
  5. How do fallbacks and circuit breakers differ and relate?

How it relates to my projects ​

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section