Model and Inference EngineeringKV cache and capacityStaff
Why can prefix-cache hit rate improve while first-token tail latency gets worse?
By Amit Kumar3 min readWorked answer includedReviewed 26 Sept 2026
The question
Interview question
After enabling prefix caching, a dashboard shows an 80-percent hit rate while p99 time to first token rises. Some prompts have long unique suffixes, and routing favors replicas with a matching prefix. Explain the possible mechanisms, define the hit-rate denominator, and design comparisons that distinguish avoided computation from queueing, cache ownership and routing effects.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Prefix caching reuses compatible attention states for an identical initial token sequence. It avoids recomputing that prefix, not generating an answer or processing the unique suffix. An answer cache instead reuses a previously produced response and has different correctness and authorization requirements. Before interpreting an 80-percent hit rate, determine whether a hit means any matching block, a fraction of queried blocks, or a fraction of input tokens whose computation was avoided.
A hypothetical request with 2,000 reused tokens followed by 50,000 new tokens has a genuine cache hit, but only about 3.85 percent of its prompt tokens are reused. Every request with that shape can count as a request-level hit while nearly all prompt computation remains. Inspect computed and reused tokens by tenant and length, then trace where the p99 request actually waited.
Exact prefix reuse does save work on matching blocks. It does not make the unique suffix free. The vLLM prefix caching design uses block hashes linked to the earlier prefix and describes eviction of cached blocks. It also supports cache salts for isolation. If tenant instructions, tool definitions, or document order change near the start, later text can look identical to a human but fail exact prefix matching. The dashboard may still count a small common header as a hit. I would compare rendered token IDs and the useful length of each matching prefix, not just the template names.
Second, retained cache blocks and live KV use the same memory budget, but the eviction rule matters. In vLLM, unused cached blocks can sit on a free queue and be evicted when active work needs those blocks. So a high cache occupancy number alone does not prove that live slots shrank. In another configuration, a reservation or slower eviction can coincide with more preemption, recomputation, and a longer admission queue. Check active and cached blocks, free blocks, evictions, preemptions, waiting tokens and queue age before and after enablement. The p99 may belong to the few long prompts that miss and wait while the common prefix traffic gets cheaper.
Third, routing can spoil locality. One replica has the hot prefix and is overloaded. Another has spare GPU capacity but a cold cache. Sticky routing to maximize hits can increase queue time more than it saves in prefill. Or requests are spread evenly, so every replica repeatedly warms the same blocks and evicts them. I would compare routing by queue estimate plus expected reused tokens against pure affinity, with a bound on how much extra waiting we accept for a hit. Cache reuse is valuable only if it reduces the entire request's wait plus compute.
The long unique suffix is the probe that forces the decision. If 2,000 shared tokens are followed by 50,000 unique ones, the cached prefix can be real and still have little effect on first token latency. Reducing unnecessary context or sending it through a different path may matter more. If the long suffix is necessary, tune chunked prefill and admission for that slice, or isolate it from short interactive requests. Do not weaken tenant cache isolation or remove a policy revision from the prefix to make the hit chart prettier.
I would A/B the feature on identical traffic and model versions, partitioned by prompt length and tenant. Record queue, prefill compute, hit tokens, eviction, preemption, and p50/p99 first token time. Run a replay that fixes routing to separate cache behavior from load balance. If p99 rises only under contention, the mechanism is probably capacity or placement. If it rises even in an isolated worker with the same prompt, inspect engine overhead and the actual cached block path. The rollout criterion is latency and cost at the required quality and privacy boundary, not a single hit percentage.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux