Back
advanced
Optimization & Deployment

Model Serving: vLLM, TGI, SGLang

Understand the production serving stack for open-weight LLMs: batching, KV cache, quantization, routing, and APIs

30 min read· serving· vLLM· TGI· deployment

Model Serving: vLLM, TGI, SGLang

Serving an LLM means turning model weights into a reliable API.

The hard part is not just loading the model. The hard part is keeping latency, throughput, cost, and reliability under control.

Serving architecture

text
client -> API gateway -> scheduler -> model workers -> tokenizer -> GPU inference -> streaming response

Core serving concepts

ConceptMeaning
prefillprocess the prompt before generation
decodegenerate new tokens one at a time
KV cachestored attention keys/values for prior tokens
continuous batchingcombine active requests dynamically
quantizationreduce memory and compute with lower precision
tensor parallelismsplit model computation across GPUs

Why KV cache matters

Every active request consumes KV cache memory. Long prompts and long generations can reduce how many users fit on the same hardware.

That is why serving engines care about:

  • cache paging
  • prefix caching
  • max context length
  • batching policy
  • memory fragmentation

Choosing a serving path

OptionBest for
hosted APIfastest product development
vLLM/TGI/SGLangopen-weight production serving
llama.cpp-style local servingedge, desktop, small models
gateway plus multiple providersreliability and routing

Production checklist

  • health checks
  • request timeouts
  • streaming support
  • token limits
  • rate limits
  • model versioning
  • logs and traces
  • rollback plan
  • capacity tests

Knowledge check

Q1: What is the KV cache?

Stored attention state that lets generation continue without recomputing all prior tokens.

Q2: Why use continuous batching?

To keep accelerators busy while serving many requests with different lengths.