SGLang's RadixAttention indexes prompt prefixes in a radix tree so deeply branched chats reuse the same KV blocks; vLLM v1 has prefix caching too, but SGLang specifically targets branching agent workloads.
Imagine a thousand people at a library all reading the same first chapter of the same book, then branching to different second chapters. The slow way: every reader gets a fresh copy of chapter 1 photocopied just for them. The fast way: one shared copy of chapter 1 sits on a central table, and everybody reads from it before walking off to their own desk for their unique chapter 2. SGLang builds that shared table for you automatically. It looks at all the conversations coming in, finds the parts they share at the start (the system prompt, the user history), and only does the work once. The other frameworks listed either solve a different problem (faster kernel launches, faster HTTP routing, smarter tokenizers) or invent a feature that does not exist. The winning move is a data structure called a radix tree that organizes the shared prefixes.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Pick a serving framework for the wrong reason and you pay it in latency tax every minute the service is up. The right way to pick is to ask: what is the dominant cost in the workload, and which framework has a first-class data structure for that cost?
For heavy multi-turn chat with shared system prompts, the dominant cost is prefill of the shared prefix. Every new turn from every user re-prefills the same 1k to 4k token system prompt unless something stops it. That something is prefix caching, and the framework that turned it into a first-class structure is SGLang, via RadixAttention.
The wrong options each describe a real optimization that targets a different cost. Sorting which optimization targets which cost is the substance of this question.
The cost shape of multi-turn chat
A typical chat request consists of three phases:
- Tokenize the input prompt (negligible, microseconds).
- Prefill: process the entire input prompt through the model to produce the KV cache. This is compute-bound and scales linearly with prompt length.
- Decode: generate output tokens one at a time. This is bandwidth-bound (each step reads all weights from HBM) and scales linearly with output length.
For a 3k-token system prompt + 200-token user message generating a 300-token reply on Llama-3-70B (FP8) on one H100, the rough split is: prefill ~200 ms, decode ~6 seconds. Decode dominates wall-clock time, but prefill dominates the controllable tax, because most of it is repeated work across users.
If every request prefills the same 3k system prompt fresh, and you serve 100 RPS, you are spending 100 * 200 ms = 20 GPU-seconds per wall-clock second just on the shared prefix. That is a brutal amount of compute to throw away. Prefix caching is the move that recovers it.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Framework | Prefix sharing strategy | Best for | Headline feature |
|---|---|---|---|
| SGLang | RadixAttention (radix tree of prefixes) | Branching agents, A/B prompts, shared system prompts | Sibling-branch KV reuse |
| vLLM v1 | Hash-based prefix cache + PagedAttention | General serving, throughput, broad coverage | Continuous batching + prefix cache |
| TensorRT-LLM | Block-level KV cache with growing prefix support | Low-latency, fixed-shape, NVIDIA-only | CUDA graphs, FP8 / FP4 kernels |
| TGI (HuggingFace) | Has prefix caching (added 2024) | Hugging Face ecosystem deployments | Easy HF Hub integration |
| Triton Inference Server | No native prefix sharing (delegates to runtime) | Multi-model gateway in front of runtimes | Model orchestration, dynamic batching |
Real products, models, and research that use this idea.
- ChatGPT-style assistants with a long system prompt see 50%+ of their prefill cost in the system prompt; prefix caching turns that into a one-time cost amortized across all users.
- Agent frameworks (LangChain, AutoGen, custom multi-agent systems) generate many sibling branches off a planning prompt; SGLang's radix tree was designed for this branching shape.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you estimate the cache hit rate for a production assistant before switching frameworks?
Log the token-id prefix of every incoming request for a day; group by prefix; compute coverage curves. If 80% of requests share a single 3k-token prefix, you have a strong case for RadixAttention. If every request is unique, prefix caching buys nothing and the framework choice swings to other axes (continuous batching, kernel performance).
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Choosing TensorRT-LLM because it sounds the fastest. CUDA graph capture optimizes kernel launch overhead for a single fixed-shape execution; it does not deduplicate KV across two different requests that happen to share a prefix.
60 second bullets to scan on the way to the call.
Describe the cost structure of multi-turn chat workloads.
Explain why prefill dominates latency for long shared prefixes.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.