Prefill, KV cache, and decode — the core loop
When a request arrives the model performs a costly initial pass called the prefill. During prefill the model reads the entire prompt and computes intermediate activations for every token. That work is not thrown away — the model stores it in GPU memory as the KV cache.- Prefill: single, heavy pass over the incoming prompt that fills the KV cache.
- KV cache: saved intermediate activations in GPU memory representing the history seen so far.
- Decode phase: the model generates the answer token-by-token and reuses the KV cache so it doesn’t rerun prefill for every new token.


The prefill+KV cache pattern is why generation time per-token is small after the first output token. Prefill does the heavy lifting once; the KV cache lets decoding reuse that work.
One message, then gone — why each request forgets
The KV cache is usually freed when a reply completes. That means the server does not persist computed state across requests by default (GPU memory is valuable and must be recycled). So each new message usually starts fresh and must be re-prefilled from the beginning of the conversation.- Turn 1: the server reads your question and fills the cache.
- Turn 2: the server re-reads turn 1 (question + answer) plus your new message and refills the cache.
- Turn 3: the server re-reads all previous turns and the new message again.

Why prefix caching matters
Prefix caching (also called prompt caching or cached prefixes) avoids re-reading the same beginning of a conversation on every request. Instead of freeing the KV cache after each reply, the server stores those cached KV blocks indexed by the text that produced them. When a later request arrives with the same beginning (the same prefix), the server reuses the cached state for that prefix and only prefill-processes the new trailing tokens.
Many hosted APIs already offer prompt or prefix caching. For example, Anthropic’s Claude API uses prompt caching to reduce cost; a cached token often costs roughly a tenth of a fresh prefill token.

Prefix caching across users — shared beginnings
A powerful property of cached computation is that it depends only on the text, not the user. If many conversations share the same initial instructions or system prompt, the server can compute that prefix once and reuse the cached KV blocks for all users who start the same way. From the model’s standpoint this is identical to reusing a prefix for subsequent turns in a single conversation.
What an inference server already does
An inference server typically performs these responsibilities:- Hold the model weights in GPU memory.
- Read the incoming prompt in a prefill burst.
- Generate the answer token-by-token during decode while reusing the KV cache.
- Optionally keep the KV cache between requests (prefix caching) so later requests can reuse work.


Practical implications and next questions
- Memory trade-offs: caching prefixes reduces compute but requires reserved GPU memory to store KV blocks.
- Shared prefixes increase throughput: identical starts across many users multiply the value of each cached prefix.
- Capacity planning: how many users can a single GPU serve depends on model size, KV cache size per token, and how many distinct prefixes must be stored.
Prefix caching lowers compute but consumes GPU memory. Servers must balance how many cached prefixes they keep versus memory needed for active inference work. Eviction policies and prefix deduplication are essential in production.