Serving
Prefix caching (self-hosted)
Reuse KV cache across requests that share a prefix: system prompt, tools, few-shot examples.
What it is and why it exists
The serving engine hashes prompt blocks and keeps their KV cache; later requests with the same prefix skip that prefill. Same idea as hosted prompt caching, under your control.
Quick prototype
—
In production, at scale
Enable in vLLM/SGLang, keep shared prefixes byte-identical, route requests with the same prefix to the same replica (prefix-aware load balancing).
Vendors and tools
| vLLM automatic prefix caching | Block-level reuse |
|---|---|
| SGLang RadixAttention | Radix tree of cached prefixes |
How it fails
- Round-robin load balancing scattering identical prefixes across replicas
What the interviewer asks next
Why route by prefix?
The cache lives on one replica’s GPU; sending similar requests to the same replica raises hit rates.