Provider Fallback Chain With Per-Target Circuit Breakers

Last updated: November 29, 2026

Quick Overview

Implement a fallback chain that sends an LLM request to an ordered list of providers, moving to the next on failure, with a circuit breaker per provider that opens after consecutive failures and allows one probe after a cooldown.

Truefoundry
Software Engineering Fundamentals
Software Engineer
Truefoundry
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement a fallback chain that sends an LLM request to an ordered list of providers, moving to the next on failure, with a circuit breaker per provider that opens after consecutive failures and allows one probe after a cooldown.

Keeping AI apps up during model or provider outages is a core promise of TrueFoundry's gateway. This question checks whether you can model the closed, open and half-open states correctly, avoid wasting latency on a provider that is known to be down, and keep the logic testable with an injected clock.

What the Interviewer Expects
  • Correct closed, open and half-open transitions
  • Only one probe request in half-open, not a thundering herd
  • Fallback skips open circuits without paying their timeout
  • Clock and transport injected so it is unit testable
  • Aggregate error returned when every target fails
Key Topics to Cover
circuit breaker
fallback
state machine
fault tolerance
testability
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Which errors should trip the breaker and which should not (for example a 400 from a bad prompt)?
  • How do you avoid retrying a non-idempotent tool-calling request?
  • Should breaker state be shared across gateway replicas?
  • How would you fall back mid-stream if the first provider dies after sending tokens?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Targets are tried in order. A target's breaker opens after threshold consecutive failures and stays open for cooldown seconds. After the cooldown it goes half-open and admits exactly one probe: su...

High-Level Design

Separate the breaker (pure state machine taking now) from the chain (iteration and error collection). send is injected, so tests can simulate timeouts without network calls. Only retryable failure...


Submit Your Answer
Markdown supported

Related Questions