Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
vLLM vs TGI vs SGLang: choosing an LLM serving engine
These three are the workhorses of open-source LLM serving. All of them do continuous batching, all of them run on GPUs, all of them will serve your model behind an OpenAI-compatible endpoint. The interesting differences live in one place: what each does with the KV cache — because on modern serving, memory management of the KV cache is where throughput is won or lost.
The one thing they have in common — and the one that splits them
vLLM, TGI (Text Generation Inference), and SGLang are all open-source LLM serving engines: they take model weights and turn them into a high-throughput, batched inference server. They all do continuous batching — dynamically packing in-flight requests onto the GPU — so on that axis they rhyme. Where they split is their signature approach to the KV cache, the per-request memory of attention keys and values that dominates GPU memory and, therefore, how many requests you can serve at once.
Continuous batching is table stakes for all three. The differentiator is KV-cache strategy: vLLM paginates it, SGLang shares it across requests, TGI wraps it in a hardened production server. Match the strategy to your workload.
Head to head
| Dimension | vLLM | TGI | SGLang |
|---|---|---|---|
| Origin | UC Berkeley → community | Hugging Face | Research → community |
| Signature trick | PagedAttention | Production-hardened server | RadixAttention (prefix reuse) |
| KV cache | Paged, low fragmentation | Standard, well-tuned | Shared across requests via a radix tree |
| Shines on | Broad, general high throughput | HF-ecosystem production deploys | Shared-prefix + structured generation |
| Structured output | Supported | Supported | First-class (frontend language) |
| Continuous batching | Yes | Yes | Yes |
| Ecosystem pull | De-facto OSS default, wide model support | Tight Hugging Face Hub integration | Agents, few-shot, complex prompting |
When to reach for each
vLLM
- A strong general-purpose default
- Broad model support out of the box
- High throughput on mixed traffic
- The largest community and integration surface
TGI
- You live in the Hugging Face ecosystem
- You want a battle-tested production server
- Tight Hub integration and tooling matter
SGLang
- Many requests share a long common prefix
- Few-shot, agents, multi-turn, tree-of-thought
- Structured / programmatic generation is central
- Prefix-cache reuse is your biggest lever
For most teams…
- Start with vLLM as the default
- Move to SGLang if prefixes repeat heavily
- Pick TGI if HF integration is decisive
The KV cache is the battleground
PagedAttention (vLLM’s idea) treats the KV cache like virtual memory: instead of one contiguous block per request — which fragments and wastes memory as sequences grow and finish — it stores the cache in fixed-size pages, so memory is packed with almost no waste. More usable KV memory means larger effective batches, which means higher throughput. It is the reason vLLM became the default.
RadixAttention (SGLang’s idea) attacks a different waste: when many requests share a prefix — the same system prompt, the same few-shot examples, the same conversation so far — recomputing and re-storing that prefix’s KV per request is pure duplication. SGLang keeps a radix tree of KV caches and shares the common prefix across requests, so it is computed once and reused. On prefix-heavy workloads (agents, few-shot, multi-turn) that is an enormous win the paged approach alone does not capture.
PagedAttention removes fragmentation waste (pack the cache tightly). RadixAttention removes duplication waste (share repeated prefixes). Different wastes — which is why the "fastest" engine depends on whether your requests share prefixes.
Why "fastest" is a workload question
Benchmarks that crown one engine are almost always measuring one workload. On generic, low-overlap traffic, vLLM’s paged memory management makes it a throughput leader. On workloads where requests share big prefixes, SGLang’s prefix reuse can pull decisively ahead — because it is skipping work the others repeat. TGI, meanwhile, optimizes for being a robust, well-integrated production server, which is a different objective than topping a synthetic throughput chart.
So the honest framing is not "X is fastest" but "fastest for what." The variables that flip the result are prefix sharing (favors SGLang), model and hardware coverage (favors vLLM’s breadth), and how much you value production ergonomics and HF integration (favors TGI). All three are fast; the right one is the one whose signature optimization matches the shape of your traffic. Benchmark on your workload, not someone else’s.
A leaderboard is a single workload in disguise. Reproduce it on your own traffic — especially your prefix-sharing pattern — before believing any ranking.
A worked scenario: a RAG service vs an agent swarm
Serve a RAG endpoint where every request stuffs different retrieved passages into the prompt: prefixes barely overlap, so prefix reuse buys little and the win comes from packing the KV cache tightly and supporting your model well. vLLM is the natural default — broad support, strong general throughput, huge community. Nothing exotic required.
Now serve an agent platform where thousands of requests share the same long system prompt, the same tool definitions, and the same few-shot scaffold, differing only in the tail: prefixes overlap massively. Here SGLang’s RadixAttention computes that shared prefix once and reuses it across the swarm, a win the paged approach alone cannot match — often the single biggest throughput lever available. Same models, same GPUs; the right engine is decided by whether your traffic repeats itself. And if the deciding factor were instead "we standardize everything on the Hugging Face stack," TGI would win on integration, not benchmark.
Low prefix overlap → vLLM. High prefix overlap (agents, few-shot, chat) → SGLang. HF-standardized production → TGI. Let the traffic shape pick the engine.
The picture: three ways to lay out the KV cache
Worked example: how many requests fit in 20 GiB of KV cache
Take a model with 32 layers and 8 KV heads of dimension 128, stored in fp16. Each token keeps a key and a value per layer, so it costs 2 × 32 × 8 × 128 × 2 bytes = 131,072 bytes (128 KiB). Say the GPU has 20 GiB left for KV cache after the weights: that is room for 163,840 tokens. Every request has a 2,000-token system prompt shared with all the others, 200 tokens of its own, and a 300-token answer, so 2,500 tokens each.
| Layout | Tokens held per request | Waste per request | Requests that fit |
|---|---|---|---|
| Contiguous, reserve 8,192 per request | 8,192 | 5,692 (69%) | 163,840 ÷ 8,192 = 20 |
| Paged, 16-token pages | 157 pages = 2,512 | 12 tokens | 163,840 ÷ 2,512 = 65 |
| Paged + shared prefix | 2,000 once, then 32 pages = 512 each | 12 tokens | (163,840 − 2,000) ÷ 512 = 316 |
Each row removes one kind of waste. Paging recovers the reservation gap, which takes the batch from 20 to 65 sequences. Sharing the prefix stops storing the same 2,000 tokens 65 times, which takes it to 316. The prefix happens to be exactly 125 pages, so it shares cleanly. Prefill compute drops by the same logic: 1,000 requests without sharing prefill 2,200,000 tokens, and with sharing 202,000, which is 91% less. Treat these as memory ceilings, not throughput. Activations, compute and your latency target cap the batch too. But they show why the KV layout, not the kernel, decides how many users one GPU can hold.
Engine trade-offs: latency, memory and what each costs
Here Time is the effect on latency and Space the effect on KV memory.
| Case | Time | Space | Why |
|---|---|---|---|
| Contiguous reservation | Simple addressing | Waste up to max_len − actual per request | The waste paged engines were built to remove. It caps the batch long before compute does. |
| PagedAttention (vLLM) | An extra block-table lookup inside attention | Under one page wasted per sequence | Packs the cache tightly, so the batch grows and throughput with it. Helps every workload. |
| RadixAttention (SGLang) | Skips prefill for a cached prefix, so the first token comes sooner | A shared prefix is stored once; old branches are evicted when memory runs short | Wins exactly when prefixes repeat. On low-overlap traffic it has nothing to share. |
| Block-level prefix caching (vLLM) | Same effect on a hit | Full pages hashed and reused | Matches whole pages from the first token, so a prefix that differs early is not reused. |
| Continuous batching (all three) | New requests join at the next step, not after the batch drains | The batch grows until KV memory is full | Why the KV layout matters at all: free memory turns straight into concurrent users. |
The decode step at batch size 1 is limited by memory bandwidth: every step reads all the weights for one token. Batching spreads that read over many sequences, which is why packing more sequences into KV memory turns directly into throughput, until compute or the latency target becomes the limit.
Common mistakes when choosing and running an engine
- Benchmarking on traffic that is not yours
Random synthetic prompts share no prefix, which hides everything RadixAttention does. Replaying one prompt a thousand times does the opposite and turns every request into a cache hit. Replay a sample of real traffic, with its real prefix overlap and its real input and output lengths.
- Assuming only SGLang can reuse a prefix
vLLM has automatic prefix caching too: it hashes full KV pages and reuses matching ones. If you compare the engines, compare them with prefix caching on in both. The structural difference that is left is how each finds and evicts shared prefixes, not whether they can.
- Putting variable content first
Both kinds of prefix reuse need the prompt to match from its first token. A timestamp or user ID at the top of the system prompt makes every request unique, so the cache never hits. Put fixed instructions, tool definitions and few-shot examples first and the per-request text last.
- Sharing the GPU without telling the engine
vLLM claims a fixed fraction of GPU memory at startup for weights and KV cache (
--gpu-memory-utilization, 0.9 by default). A second process on the same card, such as an embedding model or another engine, will run out of memory. Lower the fraction deliberately, or give each process its own GPU. - Optimising throughput and ignoring latency
The biggest batch gives the best tokens per second and the worst time to first token. Compare engines at a fixed latency target, for example the highest throughput while p99 time to first token stays under your limit, not at their unconstrained peaks.
Where this shows up in production and interviews
- Self-hosted, OpenAI-compatible endpoints
All three expose an OpenAI-style API, so an application can move from a hosted model to a self-hosted one, or between engines, by changing the base URL. That makes a bake-off on your own traffic cheap. Run it before you commit.
- Multi-turn chat and agents
Every turn of a conversation resends everything before it, so the history is a prefix that grows. An agent loop resends the same tools and instructions on every step. This is the traffic where prefix reuse pays most, and where the order of the prompt matters most.
- Capacity planning
The worked example is the core of GPU sizing: KV bytes per token × tokens per request × concurrent requests must fit in the memory left after the weights. Quantising the KV cache, or a model with fewer KV heads, changes the first number. Shorter outputs change the second.
- Interviews
Two questions come up again and again. “Why does the KV cache limit batch size?”: write the bytes-per-token formula and divide. “Explain PagedAttention”: it is virtual memory for attention. A block table maps a sequence’s logical pages to physical ones, so they need not be contiguous and can be shared.
Which would you pick?
Three situations. Pick the side you'd actually build — the explanation follows.
Your traffic is agent loops and few-shot prompts — most requests share a long identical prefix.
All three do continuous batching; the differentiator is KV-cache strategy, and high prefix overlap is exactly what cross-request sharing exploits. Paging the cache reduces fragmentation without deduplicating a prefix a thousand requests have in common.
A benchmark leaderboard shows one engine clearly ahead. How much should that decide?
The ranking depends heavily on the traffic shape used to produce it — above all the prefix-sharing pattern, which is precisely where these engines differ. Matching the model controls one variable and leaves the one that actually decides the ranking free.
Requests are independent with little prefix overlap, and you want strong memory efficiency.
With little overlap there is nothing to share, so a strategy built around cross-request reuse has no advantage to offer — paging the KV cache to remove fragmentation does. Sharing is not strictly better; it is better on traffic that shares.
Quick answers
What is the difference between vLLM, TGI and SGLang?
All three are open-source LLM serving engines that do continuous batching, but they differ in their signature KV-cache strategy. vLLM introduced PagedAttention, which stores the KV cache in fixed-size pages to eliminate memory fragmentation and enable larger batches. SGLang uses RadixAttention to share the KV cache of common prefixes across requests. TGI (Text Generation Inference) is Hugging Face’s production-hardened server with tight Hub integration. The KV-cache approach is the real differentiator.
Which is the fastest LLM serving engine?
It depends on the workload. On generic, low-prefix-overlap traffic, vLLM’s paged memory management makes it a throughput leader. On workloads where requests share large prefixes — agents, few-shot, multi-turn chat — SGLang’s RadixAttention prefix reuse can pull decisively ahead by skipping duplicated work. TGI optimizes for robust production serving rather than topping synthetic charts. Benchmark on your own traffic, because a single leaderboard is one workload in disguise.
What is the difference between PagedAttention and RadixAttention?
They remove different kinds of waste. PagedAttention (vLLM) removes fragmentation waste by storing the KV cache in fixed-size pages so memory is packed tightly, allowing bigger batches. RadixAttention (SGLang) removes duplication waste by keeping a radix tree of KV caches and sharing a common prefix across requests so it is computed once. Paging helps every workload; prefix sharing helps specifically when requests overlap.
Which should I start with?
vLLM is a strong general-purpose default with the broadest model support and community. Move to SGLang if your requests share long prefixes (agent systems, few-shot, chat), where its prefix reuse is often the single biggest throughput lever. Choose TGI when tight Hugging Face ecosystem integration and a battle-tested production server are the deciding factors over raw benchmark numbers.
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Prompting HandbookA friendly, hands-on field guide for everyday humans — learn the CRISP framework, spot bad prompts, practice with real recipes, play a drag-and-drop game, and test yourself with a quiz. No code required.Read →
- The Senior AI Engineer Interview Handbook60 questions across architecture, production incidents, agentic systems, RAG, evals, cost, safety, and leadership — what staff-level AI interviewers actually probe for.Read →
- The LLM Serving HandbookHow to serve large language models fast and cheap — prefill vs decode, the KV cache, continuous batching and PagedAttention (vLLM), quantization, speculative decoding, and the latency-vs-throughput tradeoffs that decide your inference bill.Read →
- The Transformers HandbookThe architecture behind every LLM, built up from scratch — tokens and embeddings, positional encoding, self-attention (query/key/value), multi-head attention, the transformer block (FFN, residuals, layer norm), and how a decoder-only model generates text autoregressively.Read →
- The Fine-Tuning HandbookWhen to fine-tune vs RAG vs prompting, full fine-tuning vs parameter-efficient methods, how LoRA and QLoRA make it cheap enough for a single GPU, why the data matters more than the method, catastrophic forgetting, and how to evaluate and decide.Read →
- The On-Device AI HandbookSmall models, everywhere: why 1–14B models got frontier-adjacent (distillation + textbook data), the napkin law of local inference (tokens/sec ≈ bandwidth ÷ bytes), quantization and the llama.cpp / GGUF / Ollama / MLX stack, the honest local-vs-cloud decision table, four hybrid patterns that ship, and the evals craft of choosing a small model that actually fits the device.Read →