@akshay_pachaar: RadixAttention, clearly explained. (how SGLang makes prefix caching highly efficient) Prefix caching sounds simple unti…
Summary
The article explains RadixAttention, a technique in SGLang that uses a radix tree to efficiently cache and reuse overlapping KV caches across branching requests in AI serving.
View Cached Full Text
Cached at: 09/12/26, 08:57 PM
RadixAttention, clearly explained.
(how SGLang makes prefix caching highly efficient)
Prefix caching sounds simple until requests start branching.
Consider an AI coding assistant serving these three conversations:
Request 1 Context: System prompt → Python repo → authentication code → “Fix this bug”
Request 2 Context: System prompt → Python repo → authentication code → “Add OAuth”
Request 3 Context: System prompt → Python repo → database code → “Optimize this query”
Now there are three ways a serving engine can handle them.
- With no prefix caching, every request starts from zero.
The system prompt and repo context are processed again for every request, even though thousands of tokens may be identical.
All that repeated prefill produces essentially the same KV state again and again.
- Simple prefix caching improves this.
The engine can cache a known shared prefix, such as the system prompt, and reuse its KV cache when another request starts with exactly the same tokens.
That already saves work.
But real workloads are not just one shared prefix followed by completely unrelated requests.
They branch.
Two requests may share the system prompt, repo context, and authentication code. Another may share only the system prompt and repo before diverging into database code.
This is where RadixAttention becomes useful.
- SGLang stores cached token sequences in a radix tree.
The common system prompt becomes the trunk.
The shared Python repo context extends that trunk.
Authentication and database context become separate branches.
Then individual user queries branch again.
When a new request arrives, SGLang walks this tree and finds the longest prefix whose KV cache already exists.
If 2,000 tokens match, it reuses 2,000 tokens.
If 8,000 match, it reuses 8,000.
Only the suffix after the point of divergence needs fresh prefill.
That is the key difference.
Simple prefix caching lets you reuse a prefix.
RadixAttention turns all the overlapping prefixes across your workload into a reusable hierarchy.
This is particularly valuable for multi-turn conversations, agent trajectories, shared system prompts, few-shot examples, and workloads where requests repeatedly branch from common histories.
SGLang keeps these KV blocks in the radix tree and evicts them using an LRU policy when memory is needed.
→ PagedAttention makes KV cache allocation efficient.
→ RadixAttention makes overlapping KV caches reusable.
I wrote the full breakdown of every attention mechanism, from Multi-Head Attention through FlashAttention and Sparse Attention, up to PagedAttention and RadixAttention.
The article is quoted below.
Similar Articles
@amitiitbhu: How does SGLang work? Read here: https://outcomeschool.com/blog/how-does-sglang-work…
An educational blog post explaining how SGLang works, including its runtime, frontend language, RadixAttention mechanism, and comparison to vLLM.
Explains how prompt caching works in LLMs, using Claude as a case study, detailing the transformer's KV cache mechanism and the cost benefits of caching static prefixes in agentic workflows.
Explains how prompt caching works in LLMs, using Claude as a case study, detailing the transformer's KV cache mechanism and the cost benefits of caching static prefixes in agentic workflows.
@akshay_pachaar: https://x.com/akshay_pachaar/status/2074502882812952666
A practitioner's guide to KV cache management, introducing the open-source LMCache architecture that cuts input token costs by 90% and speeds up LLM inference by up to 14x by eliminating redundant context processing in agentic workflows.
@akshay_pachaar: every inference engine makes the same mistake. an inference engine like vLLM or SGLang is the software sitting between …
LMCache is an open-source KV cache management layer that separates cache I/O from compute, plugging into vLLM, SGLang, and TensorRT-LLM to achieve up to 14x faster time-to-first-token and 4x faster decoding by parallelizing cache lookups and sharing GPU memory.
@akshay_pachaar: 90% of your KV cache never gets reused. (prompt caching was never meant to fix it) if your system prompt and tool defin…
CacheBlend, a EuroSys 2025 Best Paper, solves the problem that 90% of KV cache is never reused due to rigid prefix-matching in prompt caching. By selectively recomputing only boundary tokens between documents, it achieves 2-4x faster multi-document processing without quality loss, implemented in the open-source LMCache layer.