KV cache explained: why it limits concurrent requests
KV cache explained: what it stores during LLM inference, why it caps how many requests run at once, and how to plan capacity for your workload.
Updated
The KV cache is the memory a language model fills while it works on one request. It holds two vectors, called keys and values, for every token in the prompt and every token written so far. Keeping that memory is what makes each new token fast to produce. It is also what limits how many requests one machine can serve at the same time, so it is the first thing to check when a serving plan fails under load.
What the KV cache stores
Transformer models use attention. For each new token, the model compares that token with every earlier token to decide what to focus on. Without a cache, the keys and values for all earlier tokens would be recalculated at every step. The cache stores them once, when each token is first processed, and reads them back on every later step.
Generation has two phases. Reading the prompt fills the cache in one pass. Writing the answer adds one entry per token and reads the whole cache each time. A short label leaves a small cache from start to finish. A long contract pasted into the prompt starts with a large cache before the model writes a single word.
The size per token depends on the model’s layout: how many layers it has, how many attention heads, and how wide each head is. Read the layout from the model’s configuration before you estimate memory, because parameter count says little about cache size. Lower precision weights do not shrink the cache by themselves. Some serving stacks can store the cache at lower precision, so check what yours supports.
The cache does not change answer quality. It changes how fast tokens come out and how many requests fit in memory. Accuracy is a separate question. Our contract benchmark, run on 510 documents with 5-fold testing, is on the full results page.
What decides how many requests fit
Each request keeps its own cache. Serving software loads the model weights first. Whatever memory is left becomes room for cache blocks. The number of requests that can run together is roughly that room divided by the cache each request holds at its current length.
Here is a worked example with hypothetical numbers. Suppose 60 GB is free for cache. A request with a long contract and a long answer peaks at about 2 GB, so the machine runs about 30 at once. The same machine handling short chat turns that peak at about 100 MB each runs about 600 at once. The machine and the model did not change. The text did.
Requests also grow while they run. A request starts with its prompt, then adds tokens as the model writes. A server that admits too many long requests can run out of room partway through generation. Good serving stacks split the cache into blocks, reuse blocks for a shared prefix, and queue new work when memory is tight. A long system prompt that repeats on every call is the best case for prefix reuse, because the shared part can be stored once instead of copied into every request.
Common mistakes
- Sizing from one request. A demo with a single call shows how fast one answer arrives, not how many fit in memory at once.
- Planning for the average length. Capacity is set by the longest requests in a burst. Average-length math looks safe until the long ones arrive together.
- Leaving output open. An unbounded answer holds cache far longer than most tasks need. A label or a short extraction should stop within a few tokens.
- Testing with short prompts. A benchmark built on short inputs understates the memory pressure from real documents.
- Ignoring the repeated prompt. A long system prompt sent with every call takes cache on every request unless the stack shares it.
- Turning the cache off to save memory. The model then recalculates earlier tokens at every step, which slows long outputs sharply. Most setups keep it on and cap its size.
How to plan for it
Work through these steps before you commit to a serving setup.
- Log real traffic. Record input length, output length and how many requests arrive together. Note the longest requests that appear in a normal week, not only the average.
- Cap output per task. Set a limit for each task type, sized to the longest good answer plus a small margin.
- Separate long and short jobs. A few long requests can fill the cache and hold back many short ones that share a queue. Route them to different limits or queues.
- Test under a burst. Send requests at the concurrency you expect in production and measure wait time, not only the speed of one answer.
- Check your stack. Confirm what your provider or serving software supports for prefix sharing and memory limits, and read its current documentation for those limits.
The main trade-off is queueing against throughput. Admitting more requests raises total output, but each one waits longer when memory is full. Holding requests back keeps waits short and leaves capacity idle. Pick the point that matches your deadlines. Throughput vs latency and concurrency in LLM serving cover that trade in more depth.
For a buyer, the number that matters is documents finished per hour inside memory limits. A fast single answer does not guarantee volume. Tokens per second is one input, not the whole answer. To turn a measured throughput into cost per document, use the LLM cost calculator.
How this affects your setup
Narrow tasks need less cache. A fine-tuned open-weight model trained for one job often writes shorter outputs and runs on a tighter prompt than a general-purpose model, which keeps each request’s cache small. Trimming instructions the task never uses has the same effect, because every token in the prompt is stored for every request.
Own Weights fine-tunes an open-weight model for one high-volume task, tests it against the current model on your data, and serves it in your cloud account or on-prem, tuned for throughput. You own the weights. The Own Weights homepage explains the process in more detail.
If you want to see what your workload would need, start with a free AI cost audit. It maps your AI calls by task and shows which ones send long prompts or ask for open-ended outputs. Use the “Book a free audit” button on this page to talk it through with our team.
Questions
What is a KV cache in an LLM?
It is memory that holds the attention keys and values for every token a request has already processed. The model reads them back instead of recalculating the whole conversation each time it writes a new token. Without it, long outputs would slow down sharply.
Does a bigger KV cache make a model smarter?
No. The cache does not change what the model knows or how accurately it answers. It only sets how much text and how many requests fit in memory at the same time.
Can you turn off the KV cache to save memory?
You can, but the model then recalculates earlier tokens at every step, which is slow. Most serving setups keep it on and manage its size instead. Whether to trade speed for memory depends on your request pattern.