You run 40 replicas of the same model behind a load balancer, and round-robin gives you a terrible prefix cache hit rate. Design the routing layer.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
The KV cache is per-replica state, so a stateless load balancer throws away the single biggest cost lever you have. The goal is cache locality without destroying load balance, and the tension between those two is the whole design.
Full worked answer with diagram
The KV cache is per-replica state, so a stateless load balancer throws away the single biggest cost lever you have. The goal is cache locality without destroying load balance, and the tension between those two is the whole design.
Key the request. Hash the longest stable prefix, block-aligned to the engine's block size, typically the system prompt plus tool definitions plus conversation history up to the latest turn. The key must include model version, quantization and LoRA adapter, since KV is not portable across them.
Route by longest prefix match. Maintain a router-side approximation of what each replica has cached, either a radix tree over prefixes (the SGLang router's approach) or consistent hashing over the first N blocks, and send the request to the replica with the longest match.
Never route on cache alone. Score candidates on something like w1 * match_length - w2 * (queue_depth + running), or take the top few cache candidates and apply power-of-two-choices on load among them. Overflow to the next best replica when the best is saturated. This is what turns a hot tenant from a hotspot into merely a warm spot.
Session affinity is the cheap 80%. Sticky routing by conversation id gets most of the benefit for chat and agents with a fraction of the machinery. Its costs: you need a graceful fallback when a replica drains or dies, and it correlates failures with sessions.
The scalable end state is a shared KV tier that any replica can fetch from, which turns the router's job from "be right" into "be approximately right", and composes with prefill/decode disaggregation, where prefix-aware routing applies to the prefill pool.
Going further: follow-up territory
Pitfalls to raise unprompted: the router's view goes stale when the engine evicts blocks, so measure the actual hit rate reported by the engine, not the router's belief. Every rolling deploy and scale-up resets caches, so stagger them and expect a TTFT and cost spike each time. And measure hit rate on tokens, not requests, since that is what you pay for.
Worth sketching. Putting the score on the page makes the cache-versus-load tension concrete, which is the thing the question is really testing.
flowchart TD
R["Request"] --> K["Key: block-aligned stable prefix<br/>plus model, quant, adapter"]
K --> M["Radix tree: longest match per replica"]
M --> S["Score = w1 x match length<br/>minus w2 x load"]
S -->|"best match saturated"| N["Overflow to the next best"]
S --> REP["Chosen replica"]
N --> REP
REP --> V["Trust the engine-reported hit rate<br/>in tokens, not the router's belief"]
What a good answer covers
- The KV cache is per-replica state, so a stateless load balancer throws away the single biggest cost…
- The goal is cache locality without destroying load balance, and the tension between those two is the…
- Hash the longest stable prefix, block-aligned to the engine's block size, typically the system prompt…
- The key must include model version, quantization and LoRA adapter, since KV is not portable across them
- Maintain a router-side approximation of what each replica has cached, either a radix tree over prefixes…
Key terms: Key the request · Route by longest prefix match · Never route on cache alone · The scalable end state
In the glossary: KV cache · Quantization · LoRA · SGLang · Router · TTFT
Interviewer follow-ups to expect
How does prefix-aware routing interact with autoscaling, and what does that do to your scale-up policy?
What hit rate would justify a shared KV tier over simple sticky sessions?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep