Inference
One request, five prices
Where a cache hit lives decides what it costs
A request arrives at a pool of GPU workers. They run the same model, from the same image, on the same hardware. Any of them can answer, so routing looks like the easy part. It isn't, because each worker remembers different things. One has most of this request's work already done and sitting in GPU memory. Another has it on a local SSD. A third has never seen anything like it. Sending the request to the right one is the difference between a first token in half a second and a first token in several seconds. This lesson prices the same request five ways.
- The request
- an agent's step: a long shared prefix, a little new text
- The prefix
- 6 chunks of KV cache, 20 MiB each (illustrative)
- Five prices
- GPU memory · host DRAM · local NVMe · remote store · miss
- Set where
- at the front door, before any GPU sees the request
Read the whole lesson as text
1. Three workers that look the same
An agent sends the next step of its loop. Like every step before it, the request starts with the same instructions and tool definitions, and ends with a few hundred new tokens. The model answers in two passes. Prefill reads the whole prompt at once and sets the time to the first token. Decode then writes the answer one token at a time. Prefill leaves something behind, the KV cache, and if that is kept, the next request that starts the same way can skip most of its prefill. So the question is not only who is free. It is who still has this prefix, and where.
- The data plane asks the endpoint picker which of three identical-looking workers should take the request.
2. Why the cache leaves the GPU
Go inside gpu-2 to see where a KV cache can end up. Every request has its own, and it grows with the length of the context. It shares GPU memory with the model weights. When that memory fills, the server either throws cache away and recomputes it later, or pushes it down into memory that is bigger, cheaper and slower. The second is now standard. A cache engine such as LMCache sits under vLLM. It gathers blocks of KV cache out of GPU memory and packs them into one chunk in host DRAM. When DRAM is under pressure it hands chunks down again, to a local SSD or to a store on other machines.
- The cache engine copies a batch of KV blocks out of GPU memory and packs them into one chunk in host memory.
- When host memory runs short, the oldest chunks are written to the local SSD.
3. Price one: already there
Start with the best case. The prefix's KV cache never left GPU memory. The scheduler looks the prefix up, finds its blocks, and attaches them to the new request. Nothing is copied and nothing is computed for those 9,000 tokens. Prefill runs over the 400 new ones only, and decode starts.
- The prefix is still in GPU memory. The request picks it up as it is.
4. Price two: host DRAM
Now the same prefix is one tier down, in host DRAM. It has to come back to the GPU before decode can read it. The GPU's copy engine pulls each chunk across PCIe. That link carries tens of gigabytes per second, so six chunks are back in a few milliseconds. It is a real cost and a small one.
- Six chunks are copied from host memory into GPU memory by the GPU's copy engine.
5. Price three: local NVMe
One tier further down the chunks are on the server's SSD. Each one has to be read into host memory first, and only then copied across PCIe. Reading a 20 MiB chunk at 1.6 GiB/s takes about 12 milliseconds, and the prefix is six of them. Could better software make the drive faster? A public benchmark tried, driving the NVMe from user space with SPDK instead of through the kernel. For small requests it helped a little. At the chunk sizes the cache really uses, both ways hit the same wall: what one drive can do.
- Each chunk is read from the SSD into host memory, about twelve milliseconds apiece.
- From host memory the chunks still have to cross PCIe into GPU memory.
6. Price four: a remote store
The cache can also live off the server altogether, in a key-value store shared by many workers. That makes a prefix reachable from any worker, which is attractive. The read now crosses the network fabric first, competes with everything else on that fabric, and comes off whatever drive the store uses. Then it crosses PCIe like the others. It is still called a hit.
- The chunks are fetched from a store on other machines, over the same network that carries everything else.
7. Price five: a miss
Last, the worker that has never seen this prefix. There is nothing to fetch from anywhere. The GPU runs prefill over all 9,400 tokens. On a long prompt that is seconds of compute, and during those seconds everyone else on that GPU slows down too. Line the five up and something stands out. Four of them count as a cache hit. The gap between the best and the worst hit is larger than the gap between some hits and the miss. Whether it is cached is the wrong question. Where it is cached, and what it costs to get back, is the right one.
- With no cache to reuse, the GPU processes the whole prompt from the first token.
8. Tier blindness
Back at the front door. Round robin ignores all of this and is as likely to send the request to the miss as to the hit. The natural fix is prefix affinity: send a prefix to a worker that has it. That is a real improvement with a blind spot. A picker that only asks whether a worker has the prefix counts an SSD hit the same as a GPU memory hit. Here gpu-1 holds the prefix on its SSD and gpu-2 holds it in GPU memory. Asked a yes or no question, both say yes.
- A picker that only asks who has the prefix may choose the worker that has to read it off an SSD.
9. Hot spot
Fix the blind spot the simple way and always choose the worker with the prefix in GPU memory. Now a different thing goes wrong. Popular prefixes are popular. Every step of every agent that shares these instructions goes to gpu-2, the one worker that cached them first. Its queue grows until waiting in it costs more than the prefill it saves. One GPU is overloaded, two are idle, and the cache made it worse.
- Every request that shares the prefix is sent to the same worker, and its queue keeps growing.
10. Weigh both, on every request
Getting it right means weighing two things against each other each time: how much prefill a worker can save, and how long the request would wait behind the work that worker already has. The F5 endpoint picker runs inline on every request and doesn't guess. It learns from KV cache events which worker holds which prefix, and reads each worker's own metrics. Load is counted in tokens, so a long prompt weighs what it costs. A worker's speed is measured as how fast it is draining its queue. A hit is valued by what it costs to fetch from the tier it is in. With gpu-2 buried, the SSD hit on idle gpu-1 is now the cheapest way to a first token.
- With gpu-2 buried in work, the picker sends this request to the idle worker that holds the prefix on its SSD.
Summary
KV cache doesn't stay in GPU memory. It spills to host DRAM, to a local SSD, to a store across the network, and each step down makes it slower to bring back. So one request has five possible prices, and four of them are called a cache hit. A router that counts requests sees none of it. One that only asks who has the prefix sends work to slow tiers and piles everything onto whoever cached it first. The price is decided when the worker is chosen, before any GPU sees the request, and the model server can't fix a bad choice afterwards. That is the job of the endpoint picker: know where each prefix is, what it costs to reach, and how long the line in front of it is.
Next lesson: Measure, don't assume