Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Batch vs real-time inference: throughput, or latency?
The whole question is whether a human is waiting for the answer. If nobody is, you can pack thousands of inputs together and squeeze every last drop of throughput out of the GPU. If someone is staring at a spinner, you optimize for the milliseconds — and give up a lot of that efficiency to get them.
The one distinction that decides everything
Batch inference runs the model over many inputs together, offline or asynchronously — a scheduled job or a queue drains a big pile of work and writes results somewhere. Nobody is waiting on any single prediction, so you optimize for throughput (predictions per second per GPU) and cost per token. Real-time inference (a.k.a. online) answers one request at a time, synchronously, while a user or a calling service waits — so you optimize for latency (time to first token, tail latency) even if it means the GPU sits underused between requests.
Is a human or a live request blocked on the result? Real-time. Is the work a bulk job whose results are consumed later? Batch. The presence or absence of someone waiting sets every other trade-off.
Head to head
| Dimension | Batch | Real-Time |
|---|---|---|
| Optimizes for | Throughput & cost/token | Latency per request |
| Latency tolerance | High — minutes to hours is fine | Low — milliseconds matter |
| Triggered by | A schedule or a queue of work | An incoming request |
| GPU utilization | High — big batches keep it busy | Lower — idle gaps between requests |
| Cost per token | Lowest | Higher |
| Batching style | Large static batches | Dynamic / continuous batching |
| Typical work | Embed a corpus, score a dataset, nightly jobs | Chat, autocomplete, live APIs |
When to use each
Reach for batch
- Embedding a whole corpus for a search index
- Scoring or classifying a large dataset offline
- Nightly report generation or bulk summarization
- Backfilling predictions over historical data
- Anything where results are consumed later, not now
Reach for real-time
- Chat assistants and interactive generation
- Autocomplete and typeahead
- Live APIs a product calls per user action
- Fraud or moderation checks in the request path
- Anything a user or upstream service waits on
Continuous batching blurs the line
The old framing — "batch is efficient, online is slow" — has softened, because modern serving engines (vLLM, TGI and friends) use continuous batching: they dynamically pack many in-flight online requests into a shared batch on the GPU, adding and removing sequences as they start and finish. That recovers much of batch inference’s throughput while serving interactive traffic at low latency. So online serving is no longer synonymous with "one request, one underused GPU." Still, a dedicated offline batch job — no latency budget at all, maximal batch size — remains the cheapest way to push a fixed pile of work through a GPU.
If the work isn’t interactive, run it as an offline batch job — it’s the lowest cost per token, full stop. Use a real-time endpoint (with continuous batching) only for the traffic that actually has someone waiting on it.
The GPU-utilization reality behind the cost
Why is batch cheaper? GPUs are throughput machines: they hit peak efficiency when they have a large batch of work to chew through in parallel, and they waste cycles when fed one small request at a time. A naive online server that runs each request alone leaves the GPU mostly idle between and within requests — you pay for the whole card but use a fraction of it. Batch inference fills the GPU: big batches mean near-100% utilization, which is exactly why cost per token drops.
Continuous batching is the clever middle path — it keeps utilization high by always topping up the batch with whatever requests are in flight, so online serving stops leaving the GPU idle. But there’s still a floor: interactive traffic is bursty and latency-bounded, so you can’t always wait to assemble a perfectly full batch. A pure offline job has no such constraint, which is why "just run it as a batch overnight" remains the move whenever latency truly doesn’t matter.
Real-time buys low latency by accepting lower GPU utilization (and higher cost per token). Batch buys maximum utilization and the lowest cost by giving up interactivity entirely.
A worked scenario: a chat product and its nightly jobs
The chat box itself is unavoidably real-time: a user typed a message and is watching for tokens, so you serve it from an online endpoint with continuous batching to keep latency low while still getting decent GPU utilization from concurrent users. Optimizing this for raw throughput at the expense of time-to-first-token would make the product feel broken, so latency wins here.
But the same product has a pile of non-interactive work: embedding the 10M documents behind its retrieval, re-scoring yesterday’s conversations for quality, generating weekly summary emails. None of that has a human waiting, so it runs as batch jobs — huge batches, maximal GPU utilization, lowest possible cost — scheduled off-peak. Same models, two serving modes, chosen per workload by the one question: is someone waiting?
Interactive path → real-time (with continuous batching). Bulk, deferred, or scheduled work → batch. Most AI products run both, and the cost win comes from correctly moving everything that can be batch off the real-time path.
The picture: why static batches leave the GPU idle
Worked example: a nightly job, priced both ways
A product summarises yesterday’s 200,000 support conversations every night: 1,500 input tokens and 150 output tokens each, and the summaries are read the next morning. Using Claude Haiku 4.5’s rates from the site’s LLM API pricing table ($1/$5 per million tokens live, $0.50/$2.50 through the Batch API), trace the bill both ways.
| Step | Quantity | Live endpoint | Batch API |
|---|---|---|---|
| 1 | Input tokens: 200,000 × 1,500 | 300M | 300M |
| 2 | Output tokens: 200,000 × 150 | 30M | 30M |
| 3 | Input cost | 300M × $1 = $300 | 300M × $0.50 = $150 |
| 4 | Output cost | 30M × $5 = $150 | 30M × $2.50 = $75 |
| 5 | Per night | $450 | $225 |
| 6 | Per month (30 nights) | $13,500 | $6,750 |
| 7 | When results land | As each call returns | Within the batch window (up to 24 hours at OpenAI and Anthropic) |
The tokens are identical, so the saving is exactly the discount: $6,750 a month for changing how the job is submitted. Row 7 is the catch. A batch API promises a window, not a time. If the summaries must be ready by 08:00 and the job starts at 01:00, a 24-hour window does not guarantee the deadline. Submit earlier, as soon as each conversation closes, or keep a fallback that sends any stragglers to the live endpoint near the deadline. The same reasoning applies when you self-host: a nightly job pushed through the live chat endpoint pays full rate and also competes with daytime users for slots, which raises their time to first token.
Latency, cost and the trade-offs between serving modes
Here Time is the latency a caller sees and Space is the cost and capacity side.
| Case | Time | Space | Why |
|---|---|---|---|
| Offline batch job (self-hosted) | Minutes to hours; no per-request target | Lowest cost per token: the batch is as big as memory allows | No one is waiting, so the scheduler only has to fill the GPU. |
| Provider Batch API | Asynchronous, up to the provider’s window | 50% off input and output at OpenAI, Anthropic and Google | You trade the deadline for the discount. |
| Real-time, one request at a time | Lowest at light load, then it queues | Worst utilisation: one sequence holds the GPU | Fine for a prototype, ruinous at scale. |
| Real-time, static batches | Adds a wait to fill the batch, and short requests wait for long ones | Better utilisation, with idle slots (16/24 in the diagram) | Works for fixed-size inputs such as images or embeddings, but poorly for generation. |
| Real-time, continuous batching | A new request joins at the next step | High utilisation; KV-cache memory caps the batch | The standard for LLM serving today. |
| Precompute and serve from a store | A key lookup | Paid once per refresh, whether or not anyone reads it | Results are as stale as the last refresh. The recommendations case on this page. |
To size a real-time endpoint, use Little’s law: requests in flight = arrival rate × time each request takes. At 50 requests a second and 4 seconds per generation, 200 sequences are in flight at any moment. That is the batch continuous batching has to hold in KV memory, so it tells you how many GPUs you need before you run a single benchmark.
Common mistakes with batch and real-time inference
- Running bulk work through the live endpoint
It is the path of least resistance, because the endpoint already exists. But a backfill of a million items through it pays full price, and it fills slots that interactive users needed, so their time to first token climbs while it runs. Give bulk work its own queue, its own capacity or the provider’s batch API.
- A batch job that cannot resume
A 40-million-row scoring job that dies at 90% and restarts from row one wastes nine-tenths of a night. Write results keyed by input ID as you go, make every write idempotent, and have the job skip IDs that already have a result. Then a crash costs minutes, not the whole run.
- Treating the batch window as a deadline
A provider batch can take up to its full window. If the morning dashboard depends on it, either submit early enough that the window ends before the deadline, or watch progress and send the unfinished remainder to the live endpoint.
- Measuring real-time with the average
The mean hides the requests that queue behind a long generation. Track p95 and p99, and track time to first token separately from total time: a user watching a stream minds the first far more than the second.
- Static batching for generation
A fixed batch finishes when its longest output does. As the diagram shows, the short sequences sit idle and new requests wait. Use an engine with continuous batching for anything that generates text, and keep static batches for fixed-size work.
Where this shows up in production and interviews
- Search and RAG indexing
One embedding model, two modes. Embedding the corpus is a batch job, re-run when documents change. Embedding the user’s query is real-time, one short input on the critical path. Both must use the same model, or the query vectors and document vectors will not match.
- Recommendations and feeds
The usual design is a hybrid. A batch job precomputes candidates for every user overnight, and a light real-time model reranks them at request time using what the user just did. Expensive work happens offline, and only cheap work happens in the request path.
- Evals and LLM-as-judge
Grading thousands of model outputs before a release is the textbook batch job. Nobody is waiting on one grade, the volume is large, and half price at the same quality is the obvious choice. Run these on the batch API by default.
- Interviews
In a design round, ask first “is anyone waiting on this result?”, then size it. For real-time, use Little’s law to get the number of sequences in flight. For batch, divide total tokens by the window to get the throughput you need. Saying which parts of a product move off the live path is usually the cost answer the interviewer wants.
Which would you pick?
Three situations. Pick the side you'd actually build — the explanation follows.
Nightly, you must score 40 million users for churn risk. The scores are read the next morning by a dashboard.
No user is blocked on a prediction, so latency per item is irrelevant and throughput is everything — which is exactly what batching large inputs through a GPU optimises for. Serving this in real time pays per-request overhead 40 million times to deliver freshness nobody reads until morning.
A fraud check that must decide before a payment is authorised.
Something is blocked and waiting, which is the definition of the real-time case. Holding payments for five minutes converts a latency problem into a checkout-abandonment problem, and reversing charges after the fact accepts the loss the model existed to prevent.
Product wants personalised recommendations "as fresh as possible." Traffic is 5,000 requests/sec and the model is expensive.
"As fresh as possible" is a preference, not a requirement — and at 5,000 req/s an expensive model per request is a cost and latency problem you have chosen for a benefit nobody has quantified. Precomputing turns it into a cheap lookup; if a measured business case for true freshness appears later, that is the moment to pay for it.
Quick answers
What's the difference between batch and real-time inference?
Batch inference runs the model over many inputs together, offline or asynchronously, optimizing for throughput and cost per token because nobody is waiting on any single result. Real-time (online) inference answers one request at a time, synchronously, while a user or service waits, so it optimizes for latency even at the cost of lower GPU utilization. The deciding question is whether something is blocked on the answer.
Why is batch inference cheaper?
GPUs reach peak efficiency on large parallel batches and waste cycles on single small requests. Batch jobs fill the GPU with big batches, pushing utilization near 100% and driving cost per token down. Real-time serving is bounded by latency and bursty traffic, so it can rarely keep the GPU as full — which is why the same tokens cost more online.
What is continuous batching?
A serving technique (used by engines like vLLM) that dynamically packs many in-flight online requests into a shared GPU batch, adding and removing sequences as they start and finish. It recovers much of batch inference’s throughput while still serving interactive traffic at low latency, so online serving is no longer synonymous with an underused GPU.
Can one system do both?
Yes, and most do. A product serves its interactive path (chat, autocomplete) from a real-time endpoint with continuous batching, and runs its bulk, deferred work (embedding a corpus, nightly scoring, summary generation) as offline batch jobs. The cost win comes from moving everything that does not need to be interactive off the real-time path.
Batch vs Realtime inference: a bus, or a taxi?
This idea in other formats
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Prompting HandbookA friendly, hands-on field guide for everyday humans — learn the CRISP framework, spot bad prompts, practice with real recipes, play a drag-and-drop game, and test yourself with a quiz. No code required.Read →
- The Senior AI Engineer Interview Handbook60 questions across architecture, production incidents, agentic systems, RAG, evals, cost, safety, and leadership — what staff-level AI interviewers actually probe for.Read →
- The LLM Serving HandbookHow to serve large language models fast and cheap — prefill vs decode, the KV cache, continuous batching and PagedAttention (vLLM), quantization, speculative decoding, and the latency-vs-throughput tradeoffs that decide your inference bill.Read →
- The Transformers HandbookThe architecture behind every LLM, built up from scratch — tokens and embeddings, positional encoding, self-attention (query/key/value), multi-head attention, the transformer block (FFN, residuals, layer norm), and how a decoder-only model generates text autoregressively.Read →
- The Fine-Tuning HandbookWhen to fine-tune vs RAG vs prompting, full fine-tuning vs parameter-efficient methods, how LoRA and QLoRA make it cheap enough for a single GPU, why the data matters more than the method, catastrophic forgetting, and how to evaluate and decide.Read →
- The On-Device AI HandbookSmall models, everywhere: why 1–14B models got frontier-adjacent (distillation + textbook data), the napkin law of local inference (tokens/sec ≈ bandwidth ÷ bytes), quantization and the llama.cpp / GGUF / Ollama / MLX stack, the honest local-vs-cloud decision table, four hybrid patterns that ship, and the evals craft of choosing a small model that actually fits the device.Read →