Back to Articles

SGLang: How RadixAttention and Prefix Caching Are Reshaping LLM Serving at Scale

[ View on GitHub ]

SGLang: How RadixAttention and Prefix Caching Are Reshaping LLM Serving at Scale

Hook

What if your LLM could remember every conversation prefix it’s ever seen and reuse those computations instantly? That’s exactly what SGLang’s RadixAttention does, and it’s already powering production deployments on 400,000+ GPUs worldwide.

Context

Traditional LLM serving frameworks treat every request as isolated work, recomputing attention states even when prompts share common prefixes. If you’re running a chatbot, RAG system, or AI agent, you’re likely serving thousands of requests daily that begin with identical system prompts, context windows, or few-shot examples. Frameworks like vLLM revolutionized throughput with continuous batching and paged attention, but they still recompute key-value (KV) caches for shared prompt segments.

SGLang emerged from research at UC Berkeley and LMSYS in 2024 to solve this exact inefficiency. By storing computed KV caches in a radix tree structure—RadixAttention—it automatically detects and reuses any previously seen prompt prefix. The impact is significant: up to 5x faster inference for workloads with repetitive patterns. But SGLang isn’t just a research prototype. It’s been battle-tested at massive scale, serving as the RL rollout backend for training frontier models and powering production deployments across NVIDIA GB200s, AMD MI300X GPUs, Google TPUs, and Ascend NPUs. The framework recently joined the PyTorch ecosystem and received the a16z Open Source AI Grant, signaling its transition from academic innovation to production infrastructure.

Technical Insight

Execution Backends

OpenAI API

Match prefix

Cache hit

Cache miss

Compute KV states

Store prefix

Reuse states

Generate tokens

Client Request

CPU Scheduler

Batching & Routing

RadixAttention

Prefix Cache Tree

Prefill Engine

Prompt Processing

Decode Engine

Token Generation

KV Cache Store

Paged Memory

Response Output

System architecture — auto-generated

The core innovation in SGLang is RadixAttention, which replaces traditional per-request KV cache management with a globally shared radix tree. When a request arrives, the scheduler traverses the tree to find the longest matching prefix, reuses those cached attention states, and only computes new tokens. This happens automatically—no manual prompt engineering required.

Here’s the conceptual flow for a multi-turn conversation deployment:

# Start server with OpenAI-compatible API
# python -m sglang.launch_server --model meta-llama/Llama-3.1-8B-Instruct --port 8000

# When processing requests with shared system prompts and conversation history,
# RadixAttention automatically caches and reuses computed attention states

Behind the scenes, RadixAttention stores KV caches in a trie structure where each node represents a token. When the system prompt “You are a helpful assistant” appears in subsequent requests, SGLang doesn’t recompute those attention states—it retrieves them from the shared cache. For conversations with long histories, this means only the latest user query requires new computation. The framework’s blog posts demonstrate up to 5x faster inference on workloads with repetitive prompt patterns.

The framework’s architecture separates concerns cleanly. The zero-overhead CPU scheduler handles request batching efficiently. It supports prefill-decode disaggregation, allowing you to split resource-intensive prompt processing (prefill) from token generation (decode) across different GPU sets. For DeepSeek deployments on 96 H100 GPUs, this architecture achieved substantial throughput improvements through large-scale expert parallelism, as detailed in the framework’s blog posts on GB200 performance.

SGLang’s structured output generation uses compressed finite state machines (FSMs) to constrain token sampling. Instead of rejection sampling, it compiles JSON schemas or regex patterns into FSMs that guide the generation process, achieving 3x faster JSON decoding as described in the framework’s blog post on compressed FSM optimization.

Hardware abstraction is another architectural strength. SGLang supports tensor parallelism, pipeline parallelism, expert parallelism for MoE models, and data parallelism through a unified runtime. The framework detects your hardware—CUDA for NVIDIA, ROCm for AMD, or JAX for TPUs—and applies backend-specific optimizations. On AMD MI300X, it leverages custom optimizations for DeepSeek’s Multi-Head Latent Attention (MLA), achieving 7x faster DeepSeek MLA performance in v0.3. On NVIDIA GB200 NVL72, the framework’s blog post on GB200 Part II reports achieving 3.8x prefill and 4.8x decode throughput improvements.

The OpenAI-compatible API means you can swap vLLM or TGI endpoints with minimal code changes. But SGLang extends beyond inference—it integrates deeply with post-training workflows. Frameworks like AReaL, Miles, and slime use SGLang for RL rollouts during RLHF, where batched generation and prefix caching significantly reduce training costs. The v0.4 release added a cache-aware load balancer that optimizes multi-node deployments.

Gotcha

SGLang’s rapid development pace is both a strength and a limitation. The project gained significant momentum starting in 2024, and while adoption is growing rapidly—24,863 GitHub stars—the ecosystem of third-party integrations may lag behind more established frameworks like vLLM. If your stack relies on specific vLLM plugins or other framework-specific connectors, you might face friction migrating. The SGLang team prioritizes cutting-edge features, which means you should carefully review release notes for potential compatibility changes.

Documentation quality varies. Core features like basic server deployment and OpenAI API compatibility are documented at docs.sglang.io. However, advanced capabilities like prefill-decode disaggregation, large-scale expert parallelism across many GPUs, and cache-aware load balancing are primarily explained through blog posts and technical articles rather than comprehensive API documentation. You’ll likely need to reference GitHub issues, the community Slack, and various blog posts to implement complex production setups.

Hardware support maturity varies by platform. NVIDIA GPUs receive extensive optimization and day-zero support for new models like DeepSeek-V3.2, Mistral Large 3, and OpenAI’s gpt-oss model, as evidenced by the frequent blog posts announcing support. AMD support via ROCm is production-ready, with detailed blog posts from AMD covering DeepSeek-R1 performance on MI300X GPUs. The README indicates TPU support through the SGLang-JAX backend that runs natively on TPU. The README also mentions Intel Xeon CPUs and Ascend NPUs as supported hardware. However, based on the frequency of optimizations and blog posts, NVIDIA GPUs appear to receive the most active development focus.

Verdict

Use SGLang if you’re serving LLMs at production scale with repetitive prompt patterns—chatbots, RAG systems, multi-turn agents, or RL training pipelines where prefix caching delivers measurable cost savings. It’s especially compelling for multi-GPU deployments where disaggregated prefill-decode or expert parallelism can unlock substantial throughput gains. Choose it when you need structured outputs (JSON, regex) with the framework’s compressed FSM optimizations, or when deploying on non-NVIDIA hardware like AMD MI300X or Google TPUs where SGLang provides cross-platform support. The framework works well in environments where you’re willing to track an actively developed project and engage with the community via Slack or GitHub. Skip SGLang if you’re doing simple, low-volume inference on a single GPU—simpler frameworks will be easier to deploy. Avoid it if you require extensive third-party integrations that may be more mature in other serving frameworks, or if your organization demands highly stable APIs over access to cutting-edge features. Also reconsider if your workload has minimal prompt overlap, as RadixAttention’s prefix caching benefits depend on having shared prompt prefixes across requests.

// ADD TO YOUR README
[![Featured on Starlog](https://starlog.is/api/badge/llm-engineering/sgl-project-sglang.svg)](https://starlog.is/api/badge-click/llm-engineering/sgl-project-sglang)