Design a Multi-Provider LLM Gateway With Budgets and Failover
Last updated: November 29, 2026
Quick Overview
Design an OpenAI-compatible gateway that fronts dozens of LLM providers and self-hosted models for an enterprise, enforcing per-team rate limits and budgets, routing and failing over between providers, and logging cost and latency for every request, while adding only a few milliseconds of overhead.
Truefoundry
November 29, 20260
0
0 solved
Design an OpenAI-compatible gateway that fronts dozens of LLM providers and self-hosted models for an enterprise, enforcing per-team rate limits and budgets, routing and failing over between providers, and logging cost and latency for every request, while adding only a few milliseconds of overhead.
This is the heart of TrueFoundry's AI Gateway product, so the interviewer expects depth on the hot path, streaming, distributed limits and the split between a central control plane and gateways deployed in customer VPCs. They are checking that you keep policy checks off the network wherever possible and degrade safely when dependencies fail.
What the Interviewer Expects
- Clear hot path with no synchronous database calls per request
- Config distribution from control plane to stateless gateway pods
- Approach to distributed rate limits and budgets with bounded error
- Streaming support and usage accounting at stream end
- Async, lossy-tolerant logging pipeline
- Explicit failure behavior when Redis, the control plane or a provider is down
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How do you enforce a hard monthly budget when usage is only known after streaming ends?
- How would you add guardrails that inspect prompts without blowing the latency target?
- How does the design change when the gateway runs in a customer VPC with no outbound access to your logs store?
- How would you support MCP tool calls through the same gateway?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Functional: one OpenAI-compatible API (chat, embeddings) that maps to many providers; virtual models with weighted routing and fallbacks; auth by API key mapped to team and user; per-key, per-team, pe...
High-Level Design
Control plane (UI, API, Postgres) owns config: keys, teams, routing rules, limits, provider credentials. It publishes versioned config snapshots over a watch stream. Gateway pods are stateless and kee...