On this page
If you're serving a model to many users on GPUs, the shortlist is usually vLLM and SGLang. Both are open source, both expose an OpenAI-compatible API, and both are fast. Headline benchmarks flip between them from release to release, so the useful question isn't "which is faster" but "which is faster for my workload, and which is easier for my team to run".
This guide explains what the two share, how their best-known ideas work underneath, where they genuinely differ, and how to run a fair comparison.
#Where they came from
vLLM started at UC Berkeley in 2023 with the PagedAttention paper, which showed that managing the KV cache like virtual memory let a server batch far more requests. It grew into the most widely used open serving engine, with a huge contributor base and support from most hardware vendors.
SGLang came out of the LMSYS group (the team behind Chatbot Arena) in late 2023. Its first big idea was RadixAttention, which reuses cached prompt prefixes automatically across requests, along with a front-end language for programs that make many related model calls. It has since become a full serving engine, popular for very large MoE deployments.
#What they share
- Continuous batching: new requests join the running batch at every step (continuous batching explained).
- Paged or block-based KV cache management, so memory isn't wasted on padding or worst-case reservations (PagedAttention explained).
- Prefix caching: shared prompt prefixes are computed once and reused.
- Chunked prefill, so long prompts don't stall other users' streams.
- Quantised weights (FP8 and common 4-bit formats), speculative decoding, tensor, pipeline and expert parallelism, multi-LoRA serving and structured (JSON-schema or grammar) output.
- Support for most popular open model architectures soon after release, on NVIDIA and, to varying degrees, AMD and other accelerators.
#Prefix reuse: the same goal, two data structures
Both engines skip prefill for tokens they've already seen. They find those tokens differently.
vLLM splits each prompt into fixed-size blocks (16 tokens by default) and identifies each block by a hash of its tokens and every token before it. If a new request's first blocks have hashes that are already in the cache, those blocks are reused. Matching happens at block granularity, so a shared prefix of 1,000 tokens reuses 62 full blocks and recomputes the last partial one.
SGLang keeps every cached sequence in a radix tree: a tree whose edges are runs of tokens. A new request walks down the tree as far as its tokens match, and everything along that path is reused. When memory runs low, the least recently used leaves are evicted first, so shared trunks (system prompts, tool definitions) tend to stay cached while one-off tails go. SGLang's scheduler can also order waiting requests to favour those that share cached prefixes, raising the hit rate further.
In practice, both reach high hit rates on well-structured traffic. The differences show up in edge cases: very branchy workloads (tree search, many samples from one prompt, agents that fork) are where the radix tree's design was aimed, and where SGLang has historically done well.
#Worked example: an agent workload
An agent sends every request with a 6,000-token prefix (system prompt, tool definitions, retrieved documents) plus about 500 new tokens of conversation. At 100 requests per second:
| Prefill tokens per second | |
|---|---|
| Without prefix reuse | |
| With full prefix reuse |
Prefix reuse removes about 92% of prefill work. On a 70B model that's the difference between several GPUs of prefill compute and a fraction of one. It also cuts time to first token, because only 500 tokens need processing before the first output token.
This is why the order of the prompt matters so much. Put stable content first (system prompt, tools, shared documents) and variable content last. A timestamp or user name at the top of the prompt breaks the shared prefix for everything after it, in either engine.
#Where they differ
| vLLM | SGLang | |
|---|---|---|
| Best-known idea | PagedAttention: KV cache in fixed-size blocks | RadixAttention: a radix tree of cached prefixes |
| Sweet spot | General-purpose serving with a very broad model and hardware matrix | Heavy prefix sharing: multi-turn chat, agents, few-shot prompts, many calls over the same documents |
| Hardware reach | NVIDIA, AMD, Google TPU, Intel and others | NVIDIA and AMD mainly |
| Ecosystem | Very large: many integrations, cloud images, Kubernetes projects (such as llm-d) | Smaller but fast-moving; popular for large MoE and disaggregated deployments |
| Programming model | Server and Python API | Server, Python API and a front-end language for multi-call programs |
Both projects borrow good ideas from each other quickly, so treat the table as tendencies, not fixed facts.
#Scheduling and CPU overhead
At high request rates, the CPU work around each GPU step (scheduling, preparing inputs, sampling, detokenising) can leave the GPU idle between steps. Both engines have rebuilt their core loops to hide this: SGLang overlaps CPU scheduling for the next step with the GPU running the current one, and vLLM's V1 engine (the default since 2025) separated the API server and the engine core into different processes and streamlined the scheduler. If you benchmarked either one before those changes, your numbers are out of date.
#Structured output
Both support JSON-schema and grammar-constrained decoding, and both can use the XGrammar backend, which compiles grammars into fast token masks. SGLang introduced "jump-forward" decoding, which skips generating tokens that the grammar forces (such as fixed JSON keys). If most of your traffic is structured output, measure both on your real schemas.
#Large MoE and disaggregation
For very large mixture-of-experts models served across many GPUs with expert parallelism and separate prefill and decode pools, SGLang has published detailed deployment recipes and is widely used. vLLM supports the same patterns and is the engine underneath llm-d. See MoE inference explained and disaggregation explained.
#Equivalent settings
Names change between versions, so check your version's documentation:
| What it controls | vLLM | SGLang |
|---|---|---|
| Start a server | vllm serve MODEL |
python -m sglang.launch_server --model-path MODEL |
| Tensor parallel size | --tensor-parallel-size |
--tp |
| GPU memory for weights plus KV | --gpu-memory-utilization |
--mem-fraction-static |
| Max concurrent requests | --max-num-seqs |
--max-running-requests |
| Chunked prefill budget | --max-num-batched-tokens |
--chunked-prefill-size |
| Max context length | --max-model-len |
--context-length |
| Quantisation | --quantization |
--quantization |
#How to choose
- Write down your workload: prompt and output length distributions, how much prefix is shared between requests, concurrency at peak, and your latency targets for time to first token and time per output token (serving metrics).
- Run both on your hardware with your model and the same quantisation, using an open-loop load generator at several request rates (benchmarking done properly). Use the same load tool for both, against their OpenAI-compatible endpoints.
- Replay real prompts, not random tokens. Random prompts have no shared prefixes, so they hide the biggest difference between the engines.
- Check the prefix cache hit rate each engine reports. If it's low, fix prompt order before comparing.
- Compare at your latency target, not at maximum throughput: the engine that serves more requests per second while meeting your P95 targets wins.
- Weigh operations: which one your platform, cloud images, monitoring and team already support, and which one you can debug.
A rule of thumb: if many requests share long prefixes (agents re-sending the same system prompt and tools, RAG over the same documents) or you're deploying a very large MoE model, test SGLang early. If you need the widest model and hardware support and the most integrations, start with vLLM.
#Common mistakes
- Benchmarking with random prompts, which removes prefix sharing entirely.
- Comparing different precisions or memory settings, such as FP8 on one engine and BF16 on the other.
- Trusting a six-month-old chart. Both engines release every few weeks.
- Leaving maximum context length at the model maximum, which reduces the concurrency either engine plans for.
#FAQ
Is SGLang faster than vLLM? Sometimes, on some workloads, in some versions; the reverse is also true. Measure your own.
Can I switch between them easily? Usually. Both serve the same Hugging Face models behind an OpenAI-compatible API. Check chat templates, tool-call parsing and sampling defaults after switching.
Which has better prefix caching? Both are good. SGLang's radix tree was designed for branchy, highly shared workloads; vLLM's hashed blocks work well for common shared-prefix patterns. Your hit rate depends more on prompt structure than on the engine.
#Go deeper
- Engines compared from the inside
- Prefix, semantic and KV caching
- vLLM vs TensorRT-LLM
- llama.cpp vs vLLM for the single-machine end of the spectrum
comparisonservingvllmsglang
Found this useful?
Send it to someone who is learning the same thing.
Preparing for an interview?
Next: learn it step by step, free
Engines compared from the inside
How vLLM, SGLang, TensorRT-LLM and llama.cpp schedule, batch and cache, side by side. A free lesson with step-through diagrams and a quiz.