Continuous Batching LLM: Faster AI Serving Explained

Continuous Batching LLM: Faster AI Serving Explained

What if the biggest speedup in large language model serving had nothing to do with a bigger GPU or a smarter model? It came from a scheduling trick. In 2022, a team of researchers asked a simple question: why does a serving system wait for the slowest request in a batch to finish before starting new work? Their answer, published as the Orca paper at OSDI 2022, introduced continuous batching (also called iteration-level scheduling or in-flight batching). It changed how modern inference engines handle traffic, and it is now a default feature in most serious LLM serving stacks. This article explains what continuous batching is, how it works under the hood, where it helps, where it hurts, and what to watch out for when you turn it on.

What Continuous Batching Actually Means

Traditional batching, sometimes called static batching, works like a bus that leaves only when full and stops only at the final destination. The server collects a group of requests, runs them together, and waits until every request in that group has generated its last token. If one request needs 900 tokens and another needs 12, the short one occupies a slot for the entire 900-token journey, doing nothing after it finishes.

Continuous batching flips this. The scheduler works at the level of a single decoding iteration, meaning one token-generation step. At each step, it checks which requests have finished and removes them, then pulls new requests from the queue and slots them into the freed space. The batch stays full, and the GPU keeps doing useful work instead of idling behind the longest sequence.

The term “continuous” refers to this continuous replacement of batch members. The same idea appears under different names across vendors: NVIDIA’s TensorRT-LLM documentation calls it in-flight batching, while research papers often say iteration-level scheduling. They describe the same mechanism.

How the Scheduler Keeps the GPU Busy

How the Scheduler Keeps the GPU Busy

To understand the gain, it helps to separate the two phases of LLM inference. The prefill phase processes the entire input prompt in parallel, which is compute-heavy. The decode phase generates output tokens one at a time, which is memory-bandwidth-heavy and, on its own, leaves much of the GPU’s compute capacity unused.

A single decode step for one request is tiny. The hardware can handle far more, but only if there is work to fill it. Static batching fills it once and then slowly drains as requests finish at different times. Continuous batching refills it constantly.

A typical iteration looks like this:

  • The scheduler checks the running batch and marks any request that emitted an end-of-sequence token or hit its length limit as complete.

  • It frees those slots and their memory.

  • It admits new requests from the waiting queue, subject to memory and batch-size limits.

  • It runs one forward pass for the mixed batch of prefill and decode work.

  • It samples the next token for each active request and repeats.

That loop runs thousands of times per second on a busy server. The practical effect is that short requests finish quickly and release their resources, while long requests keep their place without blocking newcomers. The original Orca work reported throughput gains of roughly 3 to 7 times over earlier serving systems on GPT-3-class models, though the exact multiplier depends heavily on model size and workload shape. Treat any single number you see quoted online with suspicion.

Why It Beats Static Batching in Practice

The core benefit is GPU utilization. Hardware is expensive, and idle cycles are wasted money. When a batch drains unevenly, the server pays for compute it never uses. Continuous batching keeps the accelerator saturated, which translates into more tokens per second per dollar.

There is a second, less obvious benefit: better behavior under mixed traffic. Real production traffic is not uniform. Some users ask for a one-line summary, others paste a contract and ask for a full review. Static batching handles this poorly because the long request dictates the pace for everyone behind it. Continuous batching lets the short requests flow through without waiting for the long ones to finish.

For teams comparing serving strategies, the choice often comes down to workload patterns rather than raw speed. A useful companion read is the breakdown on choosing between batch and real-time inference, which covers when offline processing makes more sense than an always-on interactive endpoint.

The Memory Problem It Creates

Continuous batching does not come free. Because many requests are active at once, their KV caches all live in GPU memory simultaneously. The KV cache stores the key and value tensors for every token a request has processed, and it grows linearly with sequence length. With dozens of concurrent requests at long context, memory pressure becomes the binding constraint.

This is where PagedAttention matters. Introduced with vLLM in the paper “Efficient Memory Management for Large Language Model Serving with PagedAttention” (SOSP 2023), it borrows the idea of virtual memory paging from operating systems. Instead of allocating one contiguous block per request, it stores the KV cache in fixed-size blocks that can sit anywhere in memory. That cuts fragmentation and lets the system pack far more concurrent requests into the same GPU.

Later refinements include chunked prefill, which splits a long prompt into pieces so it does not stall decode steps, and prefill-decode disaggregation, which runs the two phases on separate hardware pools. Both are active research areas, and the details shift quickly. If you are planning capacity, check current documentation rather than relying on a blog post from two years ago.

Where You Will Encounter It

Continuous batching is no longer exotic. It is baked into the mainstream open-source serving engines.

Engine Terminology Notable pairing
vLLM Continuous batching PagedAttention for KV cache
TensorRT-LLM In-flight batching NVIDIA-optimized kernels
Text Generation Inference Continuous batching Hugging Face model ecosystem
Orca (research) Iteration-level scheduling Original 2022 prototype

If you deploy through a managed API, the provider almost certainly uses some variant of this internally, even if the documentation never names it. If you self-host, the engine you pick determines how much tuning you can do. The scheduling policy, maximum batch size, and memory allocation strategy are usually configurable, and the defaults are not always right for your traffic.

The Trade-Off Nobody Mentions First

Here is the part that surprises people. Continuous batching optimizes throughput, not per-request latency. Those are different goals, and they can pull in opposite directions.

Under heavy load, a request may wait in the queue for a slot, and once admitted it competes with many other requests for compute in every iteration. The result is that tail latency can rise even as total throughput climbs. The median user may see fast responses while the slowest 1 percent wait noticeably longer. For a chatbot, that is usually acceptable. For a real-time voice assistant or an interactive coding tool where perceived responsiveness matters, it can be a problem.

The practical fix is not to disable continuous batching but to tune it. Lower the maximum batch size to protect latency. Cap the number of concurrent requests. Prioritize certain request classes. Many teams run separate pools for interactive and background traffic so that a batch job never starves a live user.

A second common mistake is ignoring sequence length distribution. If your traffic is dominated by very long prompts, prefill work can crowd out decode steps and make the whole system feel sluggish. Chunked prefill exists precisely to smooth this out. Measure your actual input and output length distribution before you tune anything.

What Actually Works When You Deploy It

A few habits separate smooth deployments from painful ones.

Start by measuring before you change anything. Capture throughput, time to first token, and tail latency at your real traffic mix. Then change one setting at a time. Batch size and memory allocation interact in ways that are hard to predict from first principles.

Watch GPU memory headroom closely. Continuous batching will happily admit requests until memory runs out, and the failure mode is ugly: preemption, recomputation, or outright errors. Leave a buffer.

Do not assume a benchmark from a vendor blog applies to your model. Numbers vary by hardware generation, model size, quantization, and whether prefill is included in the measurement. A speedup measured on one accelerator with one sequence length distribution tells you little about another.

Finally, keep an eye on the broader serving ecosystem, since scheduling policies and memory managers change fast. Industry coverage on news about inference infrastructure is a reasonable way to track shifts, and deeper technical write-ups on the 9481.org blog go into implementation detail that release notes skip.

How It Compares to Other Optimizations

Continuous batching is one lever among several, and it is worth knowing where it sits.

Quantization reduces the precision of weights and activations, cutting memory use and speeding up each forward pass. It stacks well with continuous batching.

Speculative decoding uses a small draft model to propose several tokens that a larger model then verifies, reducing the number of sequential steps. It targets latency per token rather than batch occupancy.

KV cache compression and eviction reduces the memory footprint of long contexts, which indirectly allows larger batches.

Prefix caching reuses computation across requests that share a system prompt, a big win in applications where every user starts with the same instructions.

None of these replaces continuous batching. They solve different bottlenecks, and mature serving stacks combine several of them. The reason continuous batching gets so much attention is that it addresses the most fundamental inefficiency: a batch that drains unevenly wastes the most expensive resource in the building.

Conclusion

Continuous batching is one of those ideas that looks obvious in hindsight. Instead of treating a batch as a fixed group that must finish together, treat it as a living set that changes at every token. The Orca paper showed the approach could multiply throughput on large models, and the open-source ecosystem turned it into a default. Today, if you are serving an LLM at any meaningful scale without it, you are likely leaving a large amount of hardware capacity on the table.

The nuance is that it is a throughput tool, not a latency guarantee. Teams that understand the difference, measure their real traffic, and tune batch sizes and memory limits accordingly get the most from it. Teams that flip it on and walk away often find themselves debugging tail latency at 2 a.m. Know which problem you are solving, and the technique will serve you well.

Frequently Asked Questions

What is continuous batching in simple terms?

It is a scheduling method for LLM servers where new requests join the running batch and finished requests leave at every token-generation step, instead of waiting for an entire batch to complete. The batch stays full, so the GPU keeps working instead of idling.

Does continuous batching reduce latency?

Not necessarily. It primarily improves throughput, meaning more total tokens per second across all users. Individual requests can actually see higher tail latency under heavy load because they compete for batch slots. Lowering the maximum batch size is the usual way to protect responsiveness.

What is the difference between continuous batching and static batching?

Static batching groups requests and waits for the slowest one to finish before starting new work, so short requests waste their slots. Continuous batching replaces finished requests immediately at each iteration, keeping utilization high and letting short jobs complete without waiting behind long ones.

Is in-flight batching the same thing as continuous batching?

Yes. In-flight batching is the term NVIDIA uses in its TensorRT-LLM documentation, and iteration-level scheduling is the term used in the original Orca research paper. All three describe the same scheduling approach.

Why does continuous batching need special memory management?

Because many requests are active at once, their KV caches all occupy GPU memory simultaneously, which causes fragmentation and pressure. Techniques like PagedAttention store the cache in fixed-size blocks so more requests fit, and chunked prefill helps prevent long prompts from stalling token generation.

Can continuous batching be combined with other optimizations?

Yes, and it usually is. Quantization, speculative decoding, prefix caching, and KV cache compression all target different bottlenecks and stack with continuous batching in mature serving engines. The right combination depends on whether your priority is throughput, latency, or cost per token.

Latest articles

Scroll to Top