Home / AI Architecture & System Design / AI System Design
How would you design a model router?
30-second answer
Classify each request by difficulty or type with a cheap model or heuristics, then send easy ones to a small model and hard ones to a large model. Alternatively, cascade: try the small model and escalate if a verifier or confidence signal is low. Measure the quality/cost frontier on an eval set, include fallbacks for provider outages, and monitor routing distribution for drift.
Try answering out loud before reading on. The walkthrough below is paced for a 40-minute interview round.
New to these terms? 7 terms on this page are explained in the glossary
0–5 min Functional requirements
A router sends each request to the cheapest model that can handle it well. Before designing it, find out what "handle it well" means and what constraints exist beyond cost.
You What product is this for, and what's the traffic like?
Interviewer A coding assistant: autocomplete, "explain this code", refactors and multi-file changes. About 10 million requests a day.
You What models do we have?
Interviewer A large, strong model and a small one that's roughly ten times cheaper and twice as fast.
You What's the goal?
Interviewer Cut cost substantially without users noticing a quality drop.
You Any constraints besides cost? For example, customers who require a specific model or region?
Interviewer Some enterprise customers require EU-hosted models. And we need to survive a provider outage.
| # | Functional requirement | Why it matters |
|---|---|---|
| F1 | For each request, choose the cheapest model expected to meet the quality bar | The core goal |
| F2 | Escalate to the large model when a cheap answer fails a check (cascade) | A safety net for routing mistakes |
| F3 | Respect hard constraints: tenant model or region requirements, feature-level overrides | Contracts and compliance come before cost |
| F4 | Fall back to another provider or model during outages | Availability |
| F5 | Keep a conversation on a consistent model unless escalation is needed | Tone and style shouldn't flip mid-conversation |
| F6 | Log every routing decision and its outcome | Training data, debugging and drift detection |
| F7 | Let users retry with the stronger model | Escape hatch, and a training signal |
5–10 min Non-functional requirements and estimates
You How do we define "users don't notice"?
Interviewer Your call.
You Then I'll define it as: on our evaluation set, the routed system scores at least 99% of the large model's quality, overall and for each request type; and online, thumbs-down and "retry with stronger model" rates don't rise significantly.
| Requirement | Target | What it forces in the design |
|---|---|---|
| Quality | ≥ 99% of large-model quality per request type | Per-type evaluation, conservative thresholds |
| Cost | ≥ 40% reduction | Most traffic must go to the small model |
| Routing overhead | ≤ 20 ms p95 | Lightweight classifier, not an LLM call |
| Availability | 99.95% | Fallback lists per route, circuit breakers |
| Compliance | 100% of constrained tenants on allowed models | Hard rules evaluated before cost routing |
Back-of-envelope estimates:
- Unit costs (illustrative): large model ~$0.02 per request, small ~$0.002.
- All large: 10M × $0.02 = $200k/day.
- Routed: 70% to small, and 10% of those escalate to large after failing a check:
- 30% direct to large: 0.3 × $0.02 = $0.006
- 70% small: 0.7 × $0.002 = $0.0014
- 7% escalated (pay large too): 0.07 × $0.02 = $0.0014
- ≈ $0.0088 per request, ~$88k/day: a 56% saving.
- Latency: routed-small requests get faster (the small model is ~2× quicker); escalated ones get slower, because they pay for both attempts. Keep escalations rare.
- Router cost: an embedding plus a logistic-regression or gradient-boosted classifier is ~5 ms on CPU; negligible.
10–18 min High-level design
You Hard constraints first, then a learned difficulty classifier, then a cheap verification step that can escalate. Outages are handled by per-route fallback lists, and every decision is logged for retraining.
Scroll sideways to see the whole diagram.
Components:
- Policy filter: applies hard rules first: tenant region, allowed models, feature overrides (e.g. autocomplete is always the small model).
- Router: embeds the request and features (feature type, length, presence of multiple files, conversation depth) and predicts the probability that the small model's answer will be acceptable.
- Small and large model clients, each with a fallback list and circuit breaker.
- Verifier: cheap checks on small-model output: code compiles, tests pass, the output matches its schema, or a small judge's score.
- Decision log: request features, route, probability, verifier result, user feedback.
- Monitor: route mix, escalation rate, per-route quality from sampled judging, cost.
Routing logic:
route(request):
candidates = policy.allowed_models(request.tenant, request.feature)
if conversation.pinned_model in candidates: return conversation.pinned_model
p_ok = router.predict(request) # P(small model is good enough)
model = SMALL if p_ok >= threshold[request.type] and SMALL in candidates else LARGE
return healthy(model) or fallback(model, candidates)
A request that escalates:
Scroll sideways to see the whole diagram.
How it works: a worked example
A study aid: three requests traced through the router: one routed to the small model, one routed straight to the large model, and one that escalates.
Request 1: feature docs_qa, tenant on the standard plan: "How do I rotate an API key?"
policy filter: allowed = [small-v3, large-v5] (no region restriction)
features: type=docs_qa, prompt_tokens=1,850, turns=1, has_code=false
router: p_ok(small) = 0.93 threshold[docs_qa] = 0.80 → SMALL
small-v3: answer in 0.9 s; verifier (schema + small judge) passes
cost: $0.002 (large would have been ~$0.02)
Request 2: feature code_review, a 6-file diff:
features: type=code_review, prompt_tokens=14,200, files=6, has_code=true
router: p_ok(small) = 0.41 threshold[code_review] = 0.85 → LARGE
large-v5: answer in 6.8 s
Request 3: feature sql_help: "Write a query for monthly active users by plan."
router: p_ok(small) = 0.82 threshold[sql_help] = 0.75 → SMALL
small-v3: returns SQL in 0.7 s
verifier: run EXPLAIN against a schema-only database → error: column "plan" does not exist
escalate: large-v5 with the same prompt + the error → valid SQL in 2.9 s
total: 3.6 s, $0.022 (paid for both attempts)
decision log: { route: "small→large", reason: "verifier_failed", p_ok: 0.82, … }
That log line becomes a training example: next week's retrained router lowers p_ok for similar SQL requests.
An outage. At 15:20 the small model's error rate hits 20%. Its circuit breaker opens; requests the router sends to SMALL go to the fallback list (small-v3 → small-alt-2 → large-v5) until health checks pass for 2 minutes.
Where each piece runs:
| Component | Runs as | Example technology | Sizing (10M requests/day) | If it fails |
|---|---|---|---|---|
| Policy filter + router | Library inside the model gateway | Embedding + logistic regression / gradient-boosted trees on CPU | ~5 ms per request | Default route: LARGE (safe, expensive) |
| Model clients | In the gateway, per provider | HTTP clients with circuit breakers | Pooled provider quotas | Fallback list per route |
| Verifiers | Per feature: compilers, schema checks, small judge | Sandboxed SQL/code runners | Only on small-model outputs | Treat as pass for low-risk features, fail for high-risk |
| Decision log | Async events | Event stream → warehouse | 10M rows/day | — |
| Retraining job | Weekly batch | Labels from verifier results, feedback and sampled judging | Hours | Keep the current router |
18–32 min Deep dive
You I'd cover how to build and tune the router, which escalation signals are trustworthy, and how to keep it working as traffic and models change.
Interviewer How do you train the router? Where do labels come from?
Deep dive 1 · Building the router
Scroll sideways to see the whole diagram.
- Sample ~50,000 real requests across all request types.
- Run both models on each.
- Label whether the small model's answer is acceptable: tests pass for code, otherwise an LLM judge compares it with the large model's answer using a rubric. Humans spot-check a few hundred to calibrate the judge.
- Train a classifier on request embeddings plus simple features. A logistic regression on embeddings is often enough and is easy to calibrate.
- Pick thresholds per request type from the quality/cost curve on held-out data:
| Threshold | Share to small | Quality vs. large | Cost per request |
|---|---|---|---|
| 0.90 | 45% | 99.8% | 0.64× |
| 0.80 | 62% | 99.4% | 0.50× |
| 0.70 | 70% | 99.1% | 0.44× |
| 0.50 | 82% | 97.2% | 0.34× |
Cost assumes 10% of small-model answers escalate. Choose the point where quality stays above 99% for every request type. Thresholds can differ: autocomplete tolerates more small-model traffic than multi-file refactors.
- Shadow the router on live traffic (log decisions, keep serving the large model), then ramp.
Interviewer You said small-model answers can escalate. What signal decides that?
Deep dive 2 · Cascades and escalation signals
Good signals are external checks; weak signals are the model's opinion of itself.
| Signal | Reliability | Cost |
|---|---|---|
| Code compiles and tests pass | High | Seconds; only where tests exist |
| Output matches its schema | High for format, says nothing about content | ~0 |
| Small judge model scores the answer | Medium; needs calibration | ~100–300 ms |
| Retrieval confidence (for RAG answers) | Medium | ~0 |
| Model's self-reported confidence | Low | ~0 |
Escalation doubles latency for that request, so a cascade only pays off when escalations are rare (≤ ~10%) and the check is cheap. When a check is slow, prefer routing straight to the large model.
Deep dive 3 · Availability and constraints
- Hard rules first: an EU-only tenant never routes to a US endpoint, even during an outage; if no allowed model is healthy, return a clear error.
- Fallback lists per route: small → alternate small provider → large; large → alternate large provider.
- Circuit breakers: open after a burst of errors or timeouts, probe periodically, close when healthy.
- Conversation pinning: keep a conversation on its model; escalate within a conversation only on failure, and stay escalated afterwards.
Deep dive 4 · Drift and monitoring (if time allows)
- Route mix: a sudden shift (say 70% → 50% small) signals changed traffic or a broken feature.
- Per-route quality: judge ~1% of small-routed answers daily; alert if quality drops.
- User signals: "retry with stronger model" clicks and thumbs-down per route. Retries are free labels for retraining.
- Model updates: when either model changes, re-run the labelling and threshold selection; an improved small model may justify a higher share.
32–37 min Trade-offs
| Decision | Chosen | Alternative | Why |
|---|---|---|---|
| Router type | Calibrated classifier on embeddings | LLM picks the route | ~5 ms vs. hundreds of ms and extra cost per request |
| Thresholds | Per request type | One global threshold | Tolerance for errors differs by task |
| Safety net | Cascade on cheap external checks | No cascade | Catches routing mistakes where checks exist |
| Escalation signal | Tests, schemas, calibrated judge | Self-reported confidence | Self-assessment is unreliable |
| Constraints | Hard rules before cost | Cost-first with exceptions | Contracts and compliance can't be traded off |
| Consistency | Pin model per conversation | Route every turn | Avoids tone and capability flips mid-conversation |
Build first: policy rules and fallbacks (useful on their own), then the logged shadow router, then serving with conservative thresholds, then the cascade for code requests that have tests.
37–40 min Wrap-up and likely follow-ups
Close with: "Hard constraints first, then a calibrated classifier that predicts whether the small model will be good enough, with thresholds chosen per request type from a quality/cost curve. Cheap external checks escalate failures, fallback lists handle outages, and decisions are logged so the router can be retrained as traffic and models change. On these numbers, that's about a 56% saving at 99% of large-model quality."
Likely follow-ups:
- How would you route among more than two models? Predict acceptability for each candidate in price order and take the cheapest above its threshold, or train a multi-class router.
- What about routing by price changes or load? Make thresholds dynamic: shift more traffic to the small model when the large one is degraded or rate-limited.
- How do you prevent the router itself becoming a single point of failure? Stateless replicas, and a default route (large model) if the router times out.
What interviewers listen for
- A clear definition of "good enough", measured per request type.
- Cost arithmetic including escalations.
- Labels from real comparisons, thresholds from a quality/cost curve.
- Trustworthy escalation signals, fallbacks and hard constraints.
Red flags
- Routing by intuition ("short prompts go to the small model") with no evaluation.
- Trusting the model's own confidence for escalation.
- Ignoring compliance constraints and outages.
Discussion
Help us improve our content — give feedback. Spotted an error, have a better explanation, or got asked a follow-up in a real interview? Share it here.