Batch vs Real-Time Inference: How AI Serving Differs
Batch inference processes large volumes of input on a schedule; real-time inference answers one request as fast as possible. How the two serving modes differ.
Batch inference runs a model over a large volume of inputs together, on a schedule or in one pass, optimizing for total throughput rather than the speed of any single answer. Real-time inference (also called online inference) answers one request at a time, as fast as possible, because a person or another system is waiting on that specific response. The same trained model can serve either mode — the difference is entirely in how requests are scheduled and how the serving infrastructure is built.
Two different optimization targets
The two modes optimize for opposite things:
- Batch inference cares about throughput — total items processed per hour, per dollar of compute. Latency for any individual item barely matters, because nothing is waiting on it in real time.
- Real-time inference cares about latency — how quickly one specific request gets an answer, often with a hard budget measured in milliseconds to a couple of seconds. Throughput still matters at the system level, but never at the expense of an individual request’s response time.
This distinction shapes almost everything downstream: hardware choice, how requests are grouped, and what “efficient” even means for the system.
How batching changes GPU utilization
Modern accelerators (GPUs, TPUs) are efficient at matrix multiplication when they’re saturated with work — processing many inputs in parallel keeps the compute units busy. A single inference request, run in isolation, typically underutilizes the hardware badly: the model weights have to be read from memory regardless of how many inputs are processed alongside them, so running one input at a time pays that memory-bandwidth cost per request instead of amortizing it.
Batch inference exploits this directly: it groups many inputs (thousands to millions) and processes them together, so the fixed cost of loading model weights is spread across the whole batch. This is why offline batch jobs can process a given volume of data far more cheaply per item than the same volume would cost if it arrived as scattered real-time requests.
Real-time serving still uses batching, just on a much shorter time horizon — dynamic batching (sometimes called continuous or in-flight batching) groups whatever requests arrived within a short window, often just milliseconds, and processes them together, then immediately starts the next micro-batch as new requests arrive. This narrows the gap with pure batch throughput while keeping individual latency in an acceptable range, and it’s a large part of what makes serving large models over an API affordable.
Where each mode is actually used
Batch inference fits workloads with no live user waiting on the specific result:
- Nightly scoring of a recommendation model against a full user catalog.
- Classifying or labeling a large stored dataset (content moderation over an archive, embedding generation for a document corpus).
- Generating vector embeddings for a retrieval index ahead of time, rather than at query time.
Real-time inference fits interactive workloads:
- A chat interface, where a user is watching tokens stream back.
- Fraud scoring on a payment as it’s being authorized.
- Autocomplete or ranking that has to return before a page renders.
Some systems use both for the same underlying model: embeddings for a document corpus are generated in batch ahead of time, while the query embedding at search time is computed in real time against that pre-built index — see retrieval-augmented generation for how these two phases fit together in a RAG pipeline.
Batch vs real-time inference
| Batch inference | Real-time inference | |
|---|---|---|
| Optimization target | Throughput, cost per item | Latency per request |
| Typical latency | Minutes to hours, doesn’t matter | Milliseconds to a few seconds |
| Hardware utilization | Near-saturated | Depends on dynamic batching effectiveness |
| Cost per item | Lowest | Highest, per unit of work |
| Failure mode | A late job delays a downstream pipeline | A slow response degrades user experience directly |
| Typical trigger | Schedule or queue depth | Live user or system request |
Latency techniques specific to real-time serving
Because real-time inference can’t rely on large batches to hide cost, serving systems lean on other techniques instead. Speculative decoding uses a smaller draft model to guess several tokens ahead and verifies them with the full model in parallel, cutting the number of sequential steps needed. Model quantization and distillation shrink the model itself, trading some accuracy for lower memory bandwidth and faster response times. Prompt caching skips recomputation for the parts of an input that repeat across requests, such as a shared system prompt. None of these are relevant to a pure batch job, where total wall-clock time for the whole run is what matters, not the response time of any single item within it.
Choosing between them
The decision usually isn’t really a choice — it follows from whether a human or a live system is waiting on the specific answer. Building a real-time-latency system for a workload that’s actually batch (nightly reprocessing of a dataset, for example) wastes money on hardware sized for worst-case concurrent load instead of steady throughput. Conversely, trying to serve a live chat interface out of a batch pipeline built for throughput means users staring at a spinner while their request waits in a queue behind unrelated work. Getting the serving mode right, matched to the actual access pattern, is usually a bigger cost and latency lever than any individual model optimization.
The takeaway
Batch and real-time inference run the same kind of model under very different constraints: batch optimizes for throughput and cost per item when nothing is waiting on an individual result, while real-time optimizes for the latency of one specific request. Dynamic batching lets real-time systems recover some of batch’s efficiency without sacrificing responsiveness, but the two modes still call for different infrastructure, different hardware sizing, and different tradeoffs. Match the serving mode to how the result will actually be consumed, not to whichever pipeline is easiest to stand up first.
Tagged
Keep reading
Chisato · · 5 min read What Is Catastrophic Forgetting in AI Fine-Tuning?
Catastrophic forgetting is when training a model on new data erases skills it already had. Why it happens during fine-tuning, and how teams work around it.
Chisato · · 4 min read What Is DPO? Direct Preference Optimization Explained
DPO tunes a language model on human preference data directly, without training a separate reward model or running reinforcement learning.
Chisato · · 4 min read What Is Constitutional AI? Training Models on Principles
Constitutional AI trains language models to critique and revise their own outputs against a written set of principles, reducing reliance on human labels.