Every time an AI chatbot writes a reply, it produces one token at a time. A token is a piece of a word. Serving that loop to many people at once is mostly a memory and scheduling problem, not a maths problem. Three ideas explain most of the speed you see today: the KV cache, PagedAttention and continuous batching.
The numbers below come from the original papers and engineering blogs, and they describe specific models and GPUs from 2023. Newer models use further tricks, but the ideas still hold.
1. The KV cache: the model keeps notes
A transformer model looks back at every earlier token when it produces the next one. Doing that from scratch for every new word would mean re-processing the whole conversation again and again.
So the model saves, for every token it has read, two vectors per layer: a key and a value. This store is the KV cache. Producing the next token then means reading those saved vectors, not rebuilding them.
It is big. In the vLLM paper (SOSP 2023), the 13-billion-parameter OPT model needs about 800 KB of KV cache per token. A single request of 2,048 tokens therefore needs about 1.6 GB. On an A100 GPU with 40 GB of memory, the model's weights take about 26 GB (65%), which leaves a little over 30% for the KV cache of every request being served.
Serving happens in two phases:
Prefill: the prompt is processed in one pass, and every layer writes keys and values for every prompt token.
Decode: one new token per step. Each step reads all the earlier keys and values. That is why decoding is limited by memory more than by compute.
2. PagedAttention: an operating-system idea
Older serving systems reserved one contiguous block of memory per request, sized for the maximum possible length. A request that reserved room for 2,048 tokens but answered in 10 left the rest empty. Gaps also formed between requests.
The vLLM paper measured how much of the KV memory in those systems held real token states: only 20.4% to 38.2%.
PagedAttention borrows paging from operating systems. The KV cache is split into small fixed-size blocks. A block table records which block holds which tokens, and the blocks do not have to sit next to each other. A request gets a new block only when it needs one, so waste is limited to its last, partly filled block. In the paper's measurement, 96.3% of KV memory then held real token states. The vLLM team's launch blog put the waste at under 4%.
When several answers are generated from the same prompt, the prompt's blocks can be shared instead of copied.
The result, from the paper: 2 to 4 times the throughput at the same latency compared with FasterTransformer and Orca. The vLLM blog also reports that LMSYS used it to cut the number of GPUs serving its traffic by 50%.
3. Continuous batching: a bus that does not wait
GPUs are efficient when they process many requests together. The simple way is static batching: start a group of requests together and run until the longest answer finishes. Requests with short answers finish early, and their seats on the GPU sit empty until the whole batch ends.
Continuous batching (the Orca paper, OSDI 2022, calls it iteration-level scheduling) checks after every decoding step: which requests have finished? Their slots are filled immediately with waiting requests.
Orca reports 36.9 times the throughput at the same level of latency, compared with NVIDIA FasterTransformer, on GPT-3 175B.
An Anyscale benchmark (22 June 2023, OPT-13B on one A100 40GB) measured 8 times the throughput of naive batching from continuous batching alone, and up to 23 times when combined with vLLM's memory optimisations.
No new hardware was involved. The gain came from a scheduling loop and better use of memory.
Bonus: prompt caching
If many requests start with exactly the same text (a long system prompt, tool definitions, a document), providers can keep the computed KV cache for that prefix for a few minutes and skip it on the next request. OpenAI's documentation says cached input is discounted by up to 95%. Anthropic's documentation prices cache reads at 0.1 times the base input price on most models. The match must be exact from the first character, so put fixed text first and changing text, such as timestamps, last.
The interview version
Cost is tokens times price, and the token count depends on the language and the tokenizer.
Decoding is memory-bound. The KV cache is the main consumer of GPU memory during serving.
Page the KV cache in fixed blocks so that memory is not reserved for tokens that never arrive.
Schedule at every step, not per batch, so short requests do not hold seats.
Sources
Kwon et al., "Efficient Memory Management for Large Language Model Serving with PagedAttention", SOSP 2023, arXiv 2309.06180.
vLLM team blog, 20 June 2023.
Yu et al., "Orca: A Distributed Serving System for Transformer-Based Generative Models", OSDI 2022.
Anyscale blog, "How continuous batching enables 23x throughput in LLM inference", 22 June 2023.
OpenAI API documentation, "Prompt caching", and Anthropic documentation, "Prompt caching", both read 12 November 2026.
How AI chat servers stay fast: KV cache, PagedAttention and continuous batching
Every time an AI chatbot writes a reply, it produces one token at a time. A token is a piece of a word. Serving that loop to many people at once is mostly a memory and scheduling problem, not a maths problem. Three ideas explain most of the speed you see today: the KV cache, PagedAttention and continuous batching.
The numbers below come from the original papers and engineering blogs, and they describe specific models and GPUs from 2023. Newer models use further tricks, but the ideas still hold.
1. The KV cache: the model keeps notes
A transformer model looks back at every earlier token when it produces the next one. Doing that from scratch for every new word would mean re-processing the whole conversation again and again.
So the model saves, for every token it has read, two vectors per layer: a key and a value. This store is the KV cache. Producing the next token then means reading those saved vectors, not rebuilding them.
It is big. In the vLLM paper (SOSP 2023), the 13-billion-parameter OPT model needs about 800 KB of KV cache per token. A single request of 2,048 tokens therefore needs about 1.6 GB. On an A100 GPU with 40 GB of memory, the model's weights take about 26 GB (65%), which leaves a little over 30% for the KV cache of every request being served.
Serving happens in two phases:
Prefill: the prompt is processed in one pass, and every layer writes keys and values for every prompt token.
Decode: one new token per step. Each step reads all the earlier keys and values. That is why decoding is limited by memory more than by compute.
2. PagedAttention: an operating-system idea
Older serving systems reserved one contiguous block of memory per request, sized for the maximum possible length. A request that reserved room for 2,048 tokens but answered in 10 left the rest empty. Gaps also formed between requests.
The vLLM paper measured how much of the KV memory in those systems held real token states: only 20.4% to 38.2%.
PagedAttention borrows paging from operating systems. The KV cache is split into small fixed-size blocks. A block table records which block holds which tokens, and the blocks do not have to sit next to each other. A request gets a new block only when it needs one, so waste is limited to its last, partly filled block. In the paper's measurement, 96.3% of KV memory then held real token states. The vLLM team's launch blog put the waste at under 4%.
When several answers are generated from the same prompt, the prompt's blocks can be shared instead of copied.
The result, from the paper: 2 to 4 times the throughput at the same latency compared with FasterTransformer and Orca. The vLLM blog also reports that LMSYS used it to cut the number of GPUs serving its traffic by 50%.
3. Continuous batching: a bus that does not wait
GPUs are efficient when they process many requests together. The simple way is static batching: start a group of requests together and run until the longest answer finishes. Requests with short answers finish early, and their seats on the GPU sit empty until the whole batch ends.
Continuous batching (the Orca paper, OSDI 2022, calls it iteration-level scheduling) checks after every decoding step: which requests have finished? Their slots are filled immediately with waiting requests.
Orca reports 36.9 times the throughput at the same level of latency, compared with NVIDIA FasterTransformer, on GPT-3 175B.
An Anyscale benchmark (22 June 2023, OPT-13B on one A100 40GB) measured 8 times the throughput of naive batching from continuous batching alone, and up to 23 times when combined with vLLM's memory optimisations.
No new hardware was involved. The gain came from a scheduling loop and better use of memory.
Bonus: prompt caching
If many requests start with exactly the same text (a long system prompt, tool definitions, a document), providers can keep the computed KV cache for that prefix for a few minutes and skip it on the next request. OpenAI's documentation says cached input is discounted by up to 95%. Anthropic's documentation prices cache reads at 0.1 times the base input price on most models. The match must be exact from the first character, so put fixed text first and changing text, such as timestamps, last.
The interview version
Cost is tokens times price, and the token count depends on the language and the tokenizer.
Decoding is memory-bound. The KV cache is the main consumer of GPU memory during serving.
Page the KV cache in fixed blocks so that memory is not reserved for tokens that never arrive.
Schedule at every step, not per batch, so short requests do not hold seats.
Sources
Kwon et al., "Efficient Memory Management for Large Language Model Serving with PagedAttention", SOSP 2023, arXiv 2309.06180.
vLLM team blog, 20 June 2023.
Yu et al., "Orca: A Distributed Serving System for Transformer-Based Generative Models", OSDI 2022.
Anyscale blog, "How continuous batching enables 23x throughput in LLM inference", 22 June 2023.
OpenAI API documentation, "Prompt caching", and Anthropic documentation, "Prompt caching", both read 12 November 2026.
© 2026 Revquix. All rights reserved.
Learn with a mentor
Top-rated mentors on Revquix, ready for a 1:1 session.
- RPRohit PariharSoftware Development Engineer at Blue Yonder5.0
- SNSudhanshu NautiyalEngineering Lead at Revquix5.0
- SKSumit Kumar BeheraSenior Consultant at EYNew
Browse all mentorsKeep reading