least-loaded to prefix-aware cut the median time to first token of multi-turn chat by 3× (from about 200 ms to about 63 ms), and that of requests sharing a long system prompt by about 2×. The tail did not get worse. With no other traffic, three routers made the same choice for every prompt (64 of 64); under load, where each router also weighs the queues it sees, for 57 of 64. With tenant isolation on, no tenant’s cache was reused by another. No model, GPU or client change: once the engines publish their KV-cache events to the agent (see What to configure), it is one line of policy.
This page explains why it works, how the algorithm was chosen, and what was measured. The workload is described in enough detail to reproduce its shape; the load generator is not published, so a re-run will not give exactly the same numbers.
How many times sooner the first token arrives with prefix-aware than with least-loaded: the median, and the 99th percentile for chat (ratio of the means of 3 runs). Setup and workload below.
Why the replica matters
Before an engine writes the first token of an answer, it must read the whole prompt: the prefill. On a long prompt, prefill is most of the wait [1]. Engines such as vLLM and SGLang keep the attention state of recent prompts in their KV cache, so a prompt that starts with tokens the engine already holds skips the prefill of that part [2][3][4]. That cache lives inside one replica. With four replicas,least-loaded sends turn 2 of a conversation to whichever replica is least busy, usually not the one that holds turn 1. The cache was there; the request went elsewhere.
Think of four librarians, each with a few books open on the desk. A reader asks to continue chapter 3. least-loaded sends the reader to the least busy librarian, who has to find the book and read from the start. prefix-aware sends the reader to the librarian who already has that book open at chapter 3, unless that one has a long queue.
The gain is largest when many requests share a long beginning: multi-turn chat (every turn repeats the conversation so far), applications with a long system prompt, RAG with the same document and different questions, and agents that fan out several requests on one context.
What to configure
The algorithm, and why this one
A router that wants to send a request to the replica holding its prefix has to answer two questions: what does each replica hold, and which of it does this request start with. The choices below were made by measuring alternatives, not by preference.What each replica holds: the engines say so
The first design hashed the start of each prompt (system prompt, tools and first user message) onto a consistent-hashing ring of replicas, bounded by load [5]. Some open-source LLM routers work this way: no state, and every router agrees. Measured on a prototype againstleast-loaded, it kept conversations together (43 of 48 conversations on one replica, against 0), but under KV pressure it was often worse: on 12k-token RAG documents, 24 % of prompt tokens served from cache against 37 %; on 64k-token prompts, median TTFT 12.5 s against 8.7 s. A hash of the beginning cannot see partial matches (same document, different first question), and it cannot see evictions: once a replica evicts a prefix, the ring keeps sending traffic there.
So the router follows what the caches actually hold. vLLM and SGLang publish an event for every block they store or evict [6]. The agent next to each engine relays them to every router, re-chunked into blocks of 64 tokens, each block’s hash chained to the blocks before it as in vLLM [3]. Each router keeps a board: block → replicas that hold it. On a prototype, 95–99.8 % of the board’s predictions were within one 16-token block of what vLLM really had in cache.
Which blocks a request starts with: no tokenization in the router
The board speaks tokens, and a request arrives as text. Three ways to bridge the two were measured on a prototype (4 replicas, mixed workload, KV 40k tokens per replica, two seeds):
The chosen approach rests on one observation: anything that can be in a cache has already passed through the site, so its tokens are already known. The router computes a keyed hash (HMAC [7]) of each message prefix of the request (system prompt, then each message), called an anchor. After serving a request, the agent gets the prompt’s tokens from the engine itself (vLLM returns them with the answer; the agent strips them before the answer leaves) and tells every router which blocks each anchor maps to. That is the memo: anchor → blocks. A new request finds its blocks through its anchors, without being tokenized. Text never seen before cannot be in any cache, so not knowing its tokens costs nothing. When the same new text arrives several times at once (fan-out), the router leaves a short pending note so the copies go to the same replica.
How the replica is chosen
- Busy replicas are excluded, whatever they hold: engine KV cache nearly full, a long engine queue, or many more requests in flight than the others. Holding a prefix is no use behind a queue: cache reuse has to be balanced against load [8].
- Each remaining candidate gets an estimated time to first token: the prompt tokens already queued on it for prefill, plus the prompt tokens it does not hold, divided by its prefill speed, plus a term for the requests it is decoding. Cached tokens count as free. Prefill speed and decode step are learned from the engines’ own counters, per model, engine and GPU.
- The lowest estimate wins. Among near-ties, the candidate that holds the most of the prompt wins, then a rendezvous hash [9] of the request’s first anchor, which every router computes the same way.
Several routers, one view
Every agent reports to every router of a site: what it served, what its engine holds, and how much prefill it has queued. The routers therefore share one view without talking to each other, and break ties the same way. A conversation whose turns arrive at different routers still finds its cache. With no other traffic the routers make the same choice; under load each router also weighs the queues it sees, so they can differ (measured below).Trust and privacy
- The router never stores prompt text or tokens. Anchors and blocks are keyed hashes [7]. Token IDs never leave the agent, and no prompt, token or hash is logged.
- Agents are checked. When an answer reports how many prompt tokens the engine served from cache, the router compares it with what the board predicted. An agent whose claims do not come true loses weight in later decisions. Blocks the engine evicted after the decision are not held against it.
- Tenants are isolated. With per-tenant cache isolation on, the engine’s cache, the anchors and the index are all scoped per tenant: one tenant’s prompt never routes on, or reuses, another’s. A cache shared between users lets one of them tell, from the response time, which prompts the others sent [12][13]; the per-tenant salt uses the engine’s own cache salt [3] to close that channel.
Measurements
Setup
- Hardware: one server with 8 × RTX 5090 32 GB; the tests use 6 of them, one replica per GPU.
- Engines: 4 × vLLM 0.31.0 and 2 × SGLang 0.5.23, each serving Qwen2.5-7B-Instruct (bf16) on one GPU, prefix caching and KV events on. The KV cache is capped at 40,000 tokens per replica (vLLM
--num-gpu-blocks-override 2500, SGLang--max-total-tokens 40000), the room a ~32B 4-bit model leaves on the same card. This puts the cache under pressure, the realistic case. One soak run uses the full cache instead. - Routers: 3 routers; each of the 6 agents connects to all 3. Every request is sent to one of the three routers in turn (below), so a conversation moves between routers.
- Comparison: the same binaries, built from the prefix-aware routing pull requests (#102–#104 and #122), and the same engines, with the policy set to
least-loadedorprefix-aware. Routers are restarted with an empty index for every run.
Workload
Five workloads run at the same time in each run, closed loop, with fresh random text in every run (a seeded generator drawing words from a 50-word English vocabulary; with the Qwen2.5 tokenizer one word is one token, so ~1,900 words are ~1,900 prompt tokens). All requests are streamed chat completions withtemperature: 0 and usage reported.
- Concurrency: at most 32 (or 64) conversations, questions or fan-out groups in flight at once across all five workloads. A chat conversation holds its slot for its 6 turns.
- Router per request: request k of a workload goes to router k mod 3; for chat, turn t of conversation c goes to router (c + t) mod 3.
- Metrics: time to first token measured by the client, from sending the request to the first streamed content; cache hit is the engine’s
cached_tokensoverprompt_tokens, summed over a workload. Three runs per configuration; tables give the range over the three.
Results
Time to first token in ms: the median (p50), except in the Chat p99 rows, which give the 99th percentile. Each cell is the range over three runs; cache hit in brackets. Concurrency 32
Concurrency 64 (the engines are saturated)
Each gain is the ratio of the means over the three runs, of the same percentile: p50, or p99 in the Chat p99 rows. Over all runs: 0 errors and 0 token IDs in any response.
Multi-turn chat: the median drops, and the tail drops with it (mean of 3 runs).
Where the time goes: more of each prompt is served from the cache instead of being computed again.
With isolation on, tenant B only reuses its own earlier prompts, as much as tenant A does with its own (59 %).
Reading the results
- The more requests share a long beginning, the larger the gain. Multi-turn chat and shared system prompts gain most. RAG gains when the document is in its own message.
- Reuse inside one message is not matched. When the document and the question are in the same user message, anchors (which cover whole messages) find nothing to reuse, and the result is the same as
least-loaded. - At saturation the gain shrinks but remains. When every replica is busy, the queue weighs more than the cache in the estimate.
- The tail does not pay for the median. Chat p99 is lower at both concurrencies. It varies by about 1.3× between runs of the same configuration, so read it over several runs.
When it does not help
- One replica per model: there is nothing to choose.
- Traffic without shared beginnings: every prompt is new, and the result is the same as
least-loaded. - Prompts much shorter than the cache block (64 tokens): little to reuse.
- Reuse inside one message, as above.
Limits of this report
- One model size (7B) on one GPU type. Larger models prefill more slowly, so a cache hit saves more time; this was not measured here.
- A synthetic workload with uniform popularity. Real traffic, where some prompts are much more popular than others, usually reuses more.
- One server, so the network between routers and agents is local.
References
- Y. Zhong et al. “DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving.” OSDI 2024. arXiv:2401.09670
- W. Kwon et al. “Efficient Memory Management for Large Language Model Serving with PagedAttention.” SOSP 2023. arXiv:2309.06180
- vLLM documentation. “Automatic Prefix Caching” (block hashes chained to their prefix; per-request cache salt). docs.vllm.ai
- L. Zheng et al. “SGLang: Efficient Execution of Structured Language Model Programs” (RadixAttention). NeurIPS 2024. arXiv:2312.07104
- V. Mirrokni, M. Thorup, M. Zadimoghaddam. “Consistent Hashing with Bounded Loads.” SODA 2018. arXiv:1608.01350
- vLLM documentation. “KV cache events” configuration. docs.vllm.ai
- H. Krawczyk, M. Bellare, R. Canetti. “HMAC: Keyed-Hashing for Message Authentication.” RFC 2104, 1997. rfc-editor.org
- V. Srivatsa et al. “Preble: Efficient Distributed Prompt Scheduling for LLM Serving.” ICLR 2025. arXiv:2407.00023
- D. G. Thaler, C. V. Ravishankar. “Using Name-Based Mappings to Increase Hit Rates” (rendezvous hashing). IEEE/ACM Transactions on Networking 6(1), 1998. doi:10.1109/90.663936
- R. Qin et al. “Mooncake: Trading More Storage for Less Computation — A KVCache-centric Architecture for Serving LLM Chatbot.” FAST 2025. usenix.org
- G. Dexter et al. “LLM Query Scheduling with Prefix Reuse and Latency Constraints.” 2025. arXiv:2502.04677
- C. Gu et al. “Auditing Prompt Caching in Language Model APIs.” ICML 2025. arXiv:2502.07776
- L. Song et al. “The Early Bird Catches the Leak: Unveiling Timing Side Channels in LLM Serving Systems.” 2024. arXiv:2409.20002

