Deployed Lab

Module 2 · Model serving and inference scaling · Chapter 05 · Free

Serving engines: what vLLM and its peers actually do

20 min1 clickable picture1 hands-on lab1 predict, 2 quick quizzes, 5-question final quiz5-min video review
In 30 seconds

The picture: the engine is air traffic control for tokens, the GPU is the runway, and the controller decides whether planes queue or flow.

What this chapter gives you
The cold open

Copperline is a made up B2B SaaS company. Its first support copilot was a naive script by Priya Nair, the staff platform engineer: load the model, take one request, generate the full answer, reply, repeat.

The fix was not a bigger GPU. It was a serving engine.

The plan for this chapter
  1. The engine pipeline, from HTTP request to streamed token.
  2. Continuous batching, and why static batches waste the GPU.
  3. The KV cache, PagedAttention and prefix caching.
  4. Chunked prefill and streaming output.
  5. The three settings an operator actually touches.
  6. The picture, a worked comparison, and a matching lab.

Next: what happens between the request landing and the first token.

Step 1: The pipeline, from HTTP request to running batch

A serving engine owns the model on the GPU. Your service sends a prompt over HTTP. Everything after that is the engine's job.

Engines in this category include vLLM, TensorRT-LLM and SGLang. They differ in details, so this chapter teaches the shared jobs, and names a feature only where it is documented for that engine.

Think of a kitchen pass: orders queue, work is grouped, dishes leave as ready. Where the picture breaks down:

Next: the scheduling idea behind the whole category.

Step 2: Continuous batching, the batch that never waits

A GPU works on many rows at once far faster than on one row. So the engine groups requests into a batch and runs one step for the group. The question is when the group changes.

vLLM documents continuous batching as a core part of its design, and the main reason an engine beats Priya's script on the same GPU.

Think of a bus versus a metro where riders get on and off at each station. Where the picture breaks down:

Next: the memory system that decides how many requests can run at once.

Step 3: The KV cache, PagedAttention and prefix caching

While a request runs, the model keeps a KV cache: stored key and value data for every token so far, so each new token is cheap to compute. It lives in GPU memory and grows with prompt and answer length.

Think of renting whole rooms versus single dorm beds. Where the picture breaks down:

Next: chunked prefill and streaming.

Step 4: Chunked prefill and streaming output

Prefill is heavy: a long prompt takes a long step, and one huge prefill pauses every other running request.

Next: the three settings that control all of this.

Step 5: The three settings an operator actually touches

Engines expose many flags, but you will tune three. Names vary by engine; the bracketed names are vLLM's documented ones.

vllm serve copperline-copilot-model \
  --max-num-seqs 128 \
  --max-num-batched-tokens 8192 \
  --gpu-memory-utilization 0.90 \
  --enable-prefix-caching

This command is illustrative. Treat the numbers as a sketch, not a recipe. The right values come from your prompt lengths, answer lengths and latency target: the sizing work in Chapter 9.

Predict first:

More sequences per step means more work per step, so per token latency rises even as throughput improves. Every running sequence also holds cache blocks, so doubling concurrency doubles cache pressure. Both effects come from the same knob.

Next: the picture, one request flowing through the engine.

Step 6: The picture, inside a serving engine

Press Next to walk a request through the engine.

Inside a serving engine A request queues, joins a running batch, grows KV cache blocks, and streams tokens back. HTTP requestprompt arrives Schedulerqueue and limits Running batchjoins and leaves KV cacheblocks in GPU RAM Streamed replytoken by token
  1. The prompt arrives over HTTP and queues. Queue time is part of user latency.
  2. The scheduler checks your limits and free blocks, then admits it when a slot is safe.
  3. Under continuous batching it joins the next step, not a fresh batch.
  4. Prefill and each token add blocks, which PagedAttention lets live anywhere in the pool.
  5. Each token streams at once. At the end, slot and blocks free up.

Next: the worked example, static versus continuous.

Step 7: Worked example, static versus continuous batching

Six requests reach the copilot at once. All figures are illustrative. One step makes one token per running request. The batch holds at most 3. A needs 8 tokens; the rest need 2 each.

1. Static, first batch. A, B and C start at step 0 and run until the longest finishes: 8 steps. B and C waste 6 steps each. All complete at time 8.

2. Static, second batch. D, E and F run steps 8 to 10. Completions: 8 + 8 + 8 + 10 + 10 + 10 = 54. Average: 54 / 6 = 9 steps.

3. Continuous. A, B and C start at step 0. B and C finish at time 2. D and E join, finishing at 4. F joins, finishing at 6. A finishes at 8.

4. Continuous totals. Completions: 2 + 2 + 4 + 4 + 6 + 8 = 26. Average: 26 / 6, about 4.3 steps.

5. The lesson. Same GPU, same requests. The average wait is less than half, because finished slots refill instead of idling.

Next: the lab, matching symptoms to fixes.

Step 8: Hands-on lab, match the symptom to the engine

Why this exercise: on call, you meet symptoms first. Name the behaviour behind each one before touching a flag.

Lab: On call, you meet symptoms first. This lab runs in your browser and needs JavaScript enabled.

What to notice

Next: a field note and the mix-ups.

Field note, November 2026

In production practice, teams moving from a hand rolled script to a dedicated engine often report the same surprise: the GPU was never the bottleneck, the scheduling was. Keep settings as a small documented set per service, changed one at a time with a latency graph open. Gains vary, so measure on your own traffic.

Mix-ups to avoid

Chapter quiz

Five questions, 70% to pass.

Review this chapter in 5 minutes

Watch the whole chapter recapped: continuous batching, PagedAttention and prefix caching, chunked prefill, and the three operator settings.

Decision rule: name what is scarce first, slots, blocks, steps or token budget, then pick the behaviour or setting that targets it.

Review

Glossary

Serving engine
Program that runs a model on the GPU and handles requests. Example: the engine behind the copilot API.
Scheduler
Engine part that picks which queued requests run next. Example: admitting one when a slot frees.
Static batching
A fixed group runs until every member finishes. Example: a 2 token answer waiting on a 200 token mate.
Continuous batching
The batch refills at every step as requests finish and arrive. Example: joining one step after a slot frees.
KV cache
Stored key and value data per token, in GPU memory during a request. Example: it grows as an answer lengthens.
PagedAttention
vLLM's block based KV cache management. Example: three small blocks, not one long reservation.
Prefix caching
Reusing blocks for a prompt start shared by many requests. Example: one system prompt computed once.
Prefill
Processing the whole prompt once before generation. Example: a long invoice prompt, one heavy step.
Chunked prefill
A long prompt split across steps, mixed with decode work. Example: a 4,000 token prompt in four chunks.
Streaming
Each token sent as it is generated. Example: text appearing word by word.
Max sequences
Engine limit on requests running at once. Example: a cap of 128.

Next: "Batching and streaming: the latency budget of a token".