5.3.7 · D1MLOps & Deployment

Foundations — Batch vs real-time inference

1,938 words9 min readBack to topic

This page assumes you know nothing. We will build every letter the parent note uses — , , slack, , , , , latency, throughput — from pictures, one at a time, each earned before the next.


0. What is "inference"?

We need this word first because everything else — batch, real-time, cost, latency — is just a way of organising when and how many presses of this button happen.


1. The two clocks: and

Every prediction lives on a timeline with two special moments.

Figure — Batch vs real-time inference

Look at the figure. Time flows left → right. The blue dot is (input born). The pink dot is (answer due). The prediction must be finished somewhere in the gap between them.

  • Why two clocks and not one? Because the whole topic is about the distance between them. If you only had one moment, there'd be no choice to make.

2. Slack — the gap that decides everything

Why does the topic need this single number? Because it is the master switch:

  • Large slack (yellow bar long): the input showed up long before the answer is due → you have time to spare → you can compute early → batch is possible.
  • Tiny slack (dots almost touching): the input arrives the instant the answer is needed → there is no "earlier" moment → you are forced into real-time.

3. Counting the work:

Picture: is the number of buttons pressed on our vending machine in one day. It's a plain count — no units, just "how many."

Why the topic needs it: cost scales with . Doing 10 predictions cheaply and doing 200 million predictions are different worlds, and is the dial between them.


4. The price of one press:

We need because it lets us compare "wasting compute on unused predictions" against "paying extra to serve on demand." Without a per-press price, no cost comparison is possible.


5. How much of it is wasted:

Here is the subtle one. In batch, you often predict for everyone, but only some people actually use their answer.

Figure — Batch vs real-time inference

Look at the bar in the figure: the whole bar is all predictions you paid for; the blue slice ( of them) is the part that did useful work; the grey slice was computed and thrown away.

  • close to : almost everything you computed was used → batch is efficient.
  • close to : you precomputed mountains of answers nobody read → batch is wasteful.

Why the topic needs it: this is the single number that penalises "predict for everyone even if they never log in." It turns wasted work into a cost you can put on a scale.


6. The cost of staying ready:

Real-time doesn't waste predictions (, you only compute when asked). But it pays a different tax.

Why the topic needs it: real-time's total per-useful-prediction cost is . Batch's is . The whole decision rule is a fight between these two, so both and must exist as named quantities.


7. Latency vs throughput — two different stopwatches

These two words sound similar and get confused constantly. They measure different things.

Figure — Batch vs real-time inference

The figure shows the difference with a checkout analogy. Top lane: one customer, timed from entry to exit — that arrow is latency. Bottom: total customers leaving per minute across all lanes — that count is throughput.


8. Staleness — why an early answer can be wrong

The topic needs this word because it is batch's fundamental weakness — the hidden cost that balances real-time's serving-infra cost.


The prerequisite map

Inference the trained machine

Arrival time t_a

Deadline t_d

Slack = t_d minus t_a

Batch vs Real-time choice

N count of predictions

Cost model

c cost per prediction

u fraction actually used

o per-request overhead

Latency one request

Latency-Throughput tradeoff

Throughput per second

Staleness

Every arrow says "you need this before you can reason about that." Slack decides whether you have a choice; the cost model and the latency/throughput trade-off decide which choice; staleness is the tax on choosing batch.


Equipment checklist

Cover the right side. If you can answer each, you're ready for the parent note.

What does "inference" mean, and how is it different from training?
Inference = using an already-trained model to make a prediction; training is when the model learns. This topic only cares about inference.
What is ?
Arrival time — the clock moment when the input first exists / becomes known.
What is ?
Deadline — the clock moment when the prediction is actually needed.
Write the formula for slack and say what it measures.
; the breathing room between knowing the input and needing the answer.
What does zero (or negative) slack force?
Zero slack forces real-time; negative slack means the task is impossible (answer needed before input exists).
What is ?
The number of predictions needed per period (e.g. per day) — a plain count.
What is ?
The compute cost of one forward pass (one prediction).
What is and what range does it live in?
Utilization — the fraction of precomputed predictions actually used, between 0 and 1.
What is ?
Per-request overhead in real-time serving: network, serialization, and keeping a warm server idle.
Latency vs throughput in one line each?
Latency = time for one request; throughput = predictions per second across the whole system.
Why do latency and throughput trade off?
Grouping requests into big batches boosts throughput but makes individual requests wait (worse latency), and vice versa.
What is staleness and which mode suffers it?
How out-of-date a stored prediction is; batch suffers it because answers are computed early and used later.