Skip to content
aiqbenchAI & Quantum Intelligence
NewsInsightsBenchmarksSkillsAsk AILearnAbout
...Loading your session
NewsInsightsBenchmarksSkillsAsk AILearnAbout
  1. Future Jobs
  2. ›
  3. AI Inference & Efficiency Engineer
  4. ›
  5. Lesson 3 of 8

Serving at Scale: Continuous Batching and Paged Attention

Advanced¶ Read · 5 min⚑ Mission · 40 min◆ Test · 5 questions✓ Checked Nov 23, 2026

You'll be able to:

You can explain why batching raises throughput almost for free during decode, what continuous (iteration-level) batching fixes compared with static batching, how PagedAttention stops KV-cache memory being wasted, and which knobs in vLLM, SGLang or TensorRT-LLM trade latency against throughput.

Throughput is the product you sell; latency is the product users feel

Module 1 established that a single decode step reads all the weights whether it serves one request or sixty. A server that handles requests one at a time is therefore wasting almost all of its hardware. Serving systems exist to fill that idle capacity without making individual users wait too long. The three ideas that matter are batching, scheduling at the granularity of a single token, and managing KV-cache memory like an operating system manages RAM.

Static batching and its failure mode

The obvious design groups incoming requests into a batch, runs prefill for all of them, then decodes step by step until every request in the batch has finished. The problem is that generation lengths vary wildly: one user asks for a word, another for an essay. With static batching the slot held by the short request sits idle until the longest request finishes, and new arrivals wait for the entire batch to drain. Measured GPU utilisation under static batching is often poor exactly because of this length variance.

Continuous (iteration-level) batching

The Orca paper from Seoul National University proposed scheduling at the level of iterations rather than requests: after each decode step, the scheduler checks which requests have finished, removes them, and admits waiting requests into the freed slots immediately. A newly admitted request needs a prefill pass; Orca handles the mix with selective batching — the parts of the model that do not care about sequence length (the linear layers) are batched across all requests, while attention is run per request. The Anyscale write-up "How Continuous Batching Enables 23x Throughput" shows the measured effect on an open model: throughput jumps because slots never idle, and tail latency improves too because requests stop waiting behind unrelated long generations.

Today every serious server (vLLM, NVIDIA TensorRT-LLM, SGLang, and Hugging Face TGI, which entered maintenance mode and was archived in March 2026) does continuous batching by default. The remaining differences are in how they schedule prefill against decode: a big incoming prompt can stall decode for everyone in the batch, so servers chunk prefill into pieces interleaved with decode steps, and some deployments separate prefill and decode onto different machines entirely.

PagedAttention: stop reserving memory you will not use

Continuous batching exposes a second problem. A request's KV cache grows as it generates, and nobody knows in advance how long the output will be. Early systems reserved a contiguous block for the maximum possible length, so most of the reserved memory was never used, and fragmentation between differently sized reservations wasted more. Fewer requests fit in memory, so the batch was smaller than the hardware could handle.

The vLLM paper by Kwon et al. borrowed virtual memory from operating systems. PagedAttention stores each request's KV cache in fixed-size blocks (say 16 tokens each) that can live anywhere in GPU memory, with a per-request block table mapping logical positions to physical blocks. Blocks are allocated on demand as tokens are generated, so waste is bounded by one partial block per request. Because blocks are referenced through a table, two requests that share a prefix (the same system prompt, or parallel samples of one prompt) can point at the same physical blocks with copy-on-write — the foundation of prefix caching in module 7. The paper reports large throughput gains at equal latency compared with the systems of the time, almost entirely from fitting more requests in memory.

The knobs you will actually turn

A worked example of the trade-off. Suppose a decode step costs 25 ms at batch size 1 and 40 ms at batch size 32 on a given GPU (the step gets slower as arithmetic starts to matter, but far less than 32×).

  1. At batch 1: 40 tokens/s per user, 40 tokens/s total.
  2. At batch 32: 25 tokens/s per user, 800 tokens/s total.
  3. Per-user speed dropped 37%; total throughput rose 20×. Cost per token fell by the same factor.

Move the batch size and watch both numbers, then compare static and continuous batching on a queue with one long answer in it:

Lab

Batching: one user's speed against the server's output

One decode step
40 ms
Each user sees
25 tokens/s
The server produces
800 tokens/s
One user's stream is slower by
37.5%
Cost per token falls by
20×

A queue of mixed lengths

Eight requests arrive together. Each number is how many tokens that answer needs. 40, 8, 200, 12, 60, 16, 24, 120

Static batching

Average wait
4.23 s
Last answer done
8.46 s
Slot-steps held by a finished request
800

Continuous batching

Average wait
1.85 s
Last answer done
5.14 s
Slot-steps held by a finished request
0

Try a question

Four requests arrive together and need 2, 5, 10 and 10 tokens. The server has two slots and every decode step takes 25 ms. With static batching, taken in that order, what is the average completion time in milliseconds?

The numbers change each time. The answer is computed by the lab.

Runs in your browser. Nothing is sent or saved.

Whether that trade is right depends on the product. The main knobs are the maximum number of concurrent sequences (vLLM's max-num-seqs, SGLang's max-running-requests), the token budget per scheduler step, the prefill chunk size, and the fraction of GPU memory handed to the KV cache. More concurrency lowers cost and raises per-user latency; a bigger KV-cache allocation allows more concurrency but leaves less headroom for activations. Tensor parallelism across GPUs reduces per-step time by splitting the weight reads, at the price of interconnect traffic every layer.

What is still unsettled

How best to co-schedule prefill and decode is an open design question: chunked prefill, priority queues and disaggregated prefill/decode each win in different traffic mixes. Fairness between users under overload, and preemption policies when memory runs out (swap the KV cache to CPU, or recompute it), are handled differently by each server and are rarely benchmarked honestly. Expect the defaults to be tuned for throughput benchmarks rather than your latency goals.

What to remember

  • Static batching wastes slots on finished requests; continuous batching re-fills slots after every token step and raises throughput and improves tail latency together.
  • PagedAttention allocates KV cache in small blocks via a block table, cutting waste to one partial block per request and enabling shared prefixes.
  • Bigger batches cut cost per token dramatically while slowing each user modestly; the concurrency limit is the main dial between the two.
  • Prefill can starve decode; chunking or separating the phases is how servers keep inter-token latency stable.

Curated Materials

1.9h

The deep work happens here — the lesson is your briefing.

  • Orca: A Distributed Serving System for Transformer-Based Generative Models (Yu et al., OSDI 2022)Paper· 45 min
  • Efficient Memory Management for Large Language Model Serving with PagedAttention (Kwon et al., the vLLM paper)Paper· 45 min
  • How Continuous Batching Enables 23x Throughput in LLM Inference (Anyscale)Tutorial· 25 min

Live on aiqbench

This lesson's subject on the rest of the site, today.

In the news, last 30 days

  • GPU decoder keeps pace with a superconducting qubit clock on a continuous stream, with NVIDIA NVQLink interconnectAlice & Bob · Dec 1
  • DeepSeek Opens Source Production-Level Ascend Inference Code36Kr · Dec 1
  • NVIDIA and Cerebras Partner to Accelerate AI Agent Inference with Two-Stage Compute Architecture36Kr · Dec 1
More news on this subject →

Go further

  • Which model is worth it?Price, speed and hardware next to capability.
  • Ask AI about this lessonOpens Ask AI with a question about this lesson, answered from the news archive with sources.
  • Agent skills for this workReady-made skills for AI coding agents, checked and rated.

Test your knowledge

5 questions in 100 seconds, on a page of its own. Read everything above first.

Test your knowledge →

Module Mission

35–45 min

Simulate a serving queue on paper or in a 40-line script: eight requests arrive at once with output lengths 10, 20, 30, …, 80 tokens, each decode step takes 20 ms regardless of batch size (up to 8), and the server holds at most 4 requests at a time. Compute total wall-clock time and average per-request completion time under (a) static batching in groups of 4 and (b) continuous batching that admits a new request the moment one finishes. Report both tables and the speed-up.

Loading your work…

← Previous lesson2. Quantization: int8, int4 and When Quality DropsNext lesson →4. Speculative Decoding and Distillation
aiqbench
AI & Quantum Intelligence© aiqbench. All rights reserved.

Feeds:RSS·JSON Feed

LanguageEnglish·Românăbeta
NewsAI & TechQuantumInsights
ExploreBenchmarksLearn
CompanyAboutTrustLegal noticeTerms of ServicePrivacy PolicyCopyright noticesData erasureReport content

The aiqbench take, the insights, the daily digest and Ask answers are written by AI models from the sources shown, without editorial review before publication. They may contain errors — check the source. How the model is used →

  • News
  • Insights
  • Ask AI
  • Benchmarks
  • Account