Visual walkthrough — Batch vs real-time inference
We will use a few symbols. Before any of them appear in an equation, we name them here in plain words:
Everything below is a story about these five.
Step 1 — The two clocks that force the whole choice
WHAT. Every prediction lives between two moments: the instant its input becomes known (, "arrival"), and the instant its answer is due (, "deadline"). The gap between them is the slack.
WHY this and not cost first? Because slack can settle the question before any arithmetic. If the answer is needed the exact instant the input appears, there is no earlier moment in which to precompute — batch is physically impossible. Cost only matters when you actually have a choice.
PICTURE. Two timelines. On top, a fraud swipe: arrival and deadline sit on top of each other — zero slack, one option. On the bottom, a recommendation: the input is known hours before the user opens the app — a wide green slack bar you could fill with precomputation.
Figure 1 — The slack gate: zero slack forces real-time; wide slack (green bar) makes batch possible.
- small (near zero) → real-time is forced, no further analysis.
- large → you may batch. Now, and only now, cost decides. Proceed to Step 2.
Step 2 — The naive cost of one prediction
WHAT. Both strategies run the identical model, so one forward pass costs the same in both. Draw as a single coin-height bar. This is our unit of everything.
WHY. We must anchor the comparison to something both sides share, so the difference between them is visible cleanly. That shared thing is , the cost of a forward pass. Everything else is a multiplier or an add-on to this one coin.
PICTURE. A single blue bar of height , labeled "one forward pass — same weights, same math, both modes." This is the mistake the parent warned about ("real-time = batch size 1") shown honestly: the math really is one bar. The difference lives in the system around it, which the next steps draw.
Figure 2 — The shared unit: one forward pass costs (assume ) in both modes.
Step 3 — Batch's hidden waste: divide by utilization
WHAT. In batch you compute all candidates, paying . But only a fraction of them get consumed — that's useful predictions. The honest cost per useful answer spreads the total bill over only the useful ones.
WHY divide, not subtract? Because we want a fair per-answer price to compare against real-time's per-answer price. You paid for ; you got value from . The price of each valuable answer is total-cost ÷ valuable-count — that is division.
- cancels — the size of the pool doesn't matter, only the fraction wasted does.
- This division is only defined because (see the definitions box). — nothing precomputed is ever used — is a forbidden division-by-zero: the "cost per useful answer" is genuinely undefined because there are no useful answers to spread the bill over.
- As (everyone's prediction gets used) → : perfect, no waste.
- As (almost nothing gets used) → : you precomputed a mountain nobody touched.
PICTURE. A pool of circles; only a -fraction glow (used), the rest are dim (wasted). Beside it, the bar stretched taller by the factor — the shorter the glowing slice, the taller the true per-answer cost climbs.
Figure 3 — Batch divides its bill by utilization ; low stretches the per-answer cost sky-high.
Step 4 — Real-time's hidden tax: the overhead
WHAT. Real-time only computes when asked, so nothing is wasted. Its own utilization — call it — is exactly 1: every answer it produces was explicitly requested, so none is discarded. But every live answer carries an extra cost : the network round-trip, packing/unpacking the request, and keeping a warm server idling so there's no cold start.
WHY add, not multiply? Because overhead is a fixed toll paid once per request, on top of the forward pass — it stacks on, it doesn't scale the compute. Addition = "and also this."
- No "divide by utilization" appears — because exactly: dividing by 1 changes nothing, so the term vanishes. (Contrast batch, where inflated the cost.)
- If (overhead negligible) → : real-time is as cheap as a lone forward pass.
- is what you pay for freshness on demand.
PICTURE. The blue bar with a red stacked on top of it — a two-segment tower labeled "compute + toll." No waste, but a permanent surcharge.
Figure 4 — Real-time wastes nothing () but stacks a fixed overhead on top of .
Step 5 — Put the two towers side by side and let them cross
WHAT. We now have two per-answer prices: and . Batch wins on cost exactly when its tower is shorter:
WHY an inequality? We don't want a single number — we want the boundary where the cheaper strategy flips. An inequality carves the world into "batch-land" and "real-time-land." Solving for tells us how much utilization you need to justify precomputing.
Solve it, one honest algebra step at a time. Recall from the definitions that and — both facts are needed to keep the inequality's direction. Divide both sides by (positive, so the direction is safe):
- Left move: divided by → turns absolute costs into ratios (the is "overhead measured in forward-passes"). Legal because .
- Right move: flipped the reciprocal → an inequality becomes . This flip is only valid because (both sides positive); dividing/reciprocating across a positive quantity preserves the direction, whereas a zero or negative would break it.
PICTURE. Two curves against on the horizontal axis: a flat red line at height (real-time, independent of ) and a falling blue curve (batch, cheaper as grows). They cross at . Left of the crossing (low utilization) the blue curve is above the red line → real-time wins. Right of it → batch wins. The crossing point is shaded.
Figure 5 — The two cost curves cross at : right of it batch wins, left of it real-time wins.
Step 6 — Read the threshold's two extremes (degenerate cases)
WHAT. A formula is only trusted once you push it to its limits and it still behaves. We test at and .
WHY. Edge cases are where wrong formulas break. If ours gives sane answers at the extremes, the whole derivation is validated.
- (real-time is almost free): threshold . You'd need near-perfect utilization to justify batch — so lean real-time. Matches intuition: if being live costs nothing, always be live.
- (real-time infra is ruinously expensive): threshold . Almost any utilization justifies batch — so precompute and cache aggressively.
- The special case (everything precomputed is used) is always any threshold below 1, so batch wins whenever there's slack. This is the recommendation case.
PICTURE. A slider of from 0 to large; the threshold marker slides from 1 (all the way right, "real-time land dominates") down to 0 (all the way left, "batch land dominates"). Two annotated snapshots.
Figure 6 — The batch threshold slides from 1 (as ) down to 0 (as ).
Step 7 — The hybrid escape hatch (why the real world isn't binary)
WHAT. Real pipelines split themselves: the slow-changing, expensive part is batched; the query-specific part is served live. A search engine batches document embeddings nightly, then does a real-time nearest-neighbor lookup at query time.
WHY. Because different parts of one pipeline have different slack. Embeddings of documents don't depend on your query → huge slack → batch. Matching your query to them exists only when you type → zero slack → real-time. Apply Steps 1–6 per component, not to the whole.
PICTURE. A pipeline splitting into two lanes: a blue "batch lane" (high slack, high utilization, Feature Store / Caching Strategies) feeding a red "real-time lane" (zero slack) at query time, using Dynamic Batching to claw back throughput.
Figure 7 — Hybrid pipeline: batch the slow, stable part; serve the live, query-specific part in real-time.
The one-picture summary
WHAT. One figure compresses the whole walkthrough: the slack gate first (does a choice even exist?), then the two cost towers and their crossing at , then the drift/staleness veto.
Figure 8 — The whole derivation in one frame: slack gate → cost crossing at → staleness veto.
Recall Feynman retelling — the whole walkthrough in plain words
Start with two alarm clocks. One rings when your ingredient arrives, the other when the meal is due. If they ring at the same time, you have no choice — cook on the spot (real-time). If the first rings hours early, you could cook ahead (batch), so now money decides. Cooking ahead means making a whole tray of dishes even though only a fraction get eaten — so each eaten dish secretly cost you , more than the plain because of the wasted trays. Cooking on the spot wastes nothing, but you pay a doorman-and-kitchen tax for keeping the stove hot all day, so each dish costs . Draw both prices as (how much gets eaten) grows: the on-the-spot price is a flat line at ; the cook-ahead price is a curve that starts sky-high (nobody eats → infinite waste) and falls as more gets eaten. They cross at exactly . To the right — lots gets eaten — cook ahead. To the left — most is wasted — cook on the spot. Push the tax to zero and the crossing slides to 1 (only bother cooking ahead if everyone eats). Push huge and it slides to 0 (cook ahead almost always). And one last warning your formula can't see: a dish cooked at midnight and served at 6 PM might be soggy — staleness can veto even the cheapest plan.
Connections
- Batch vs real-time inference — the parent topic this walkthrough visualizes.
- Latency and Throughput — the trade-off hiding behind and batch's fill-wait.
- Feature Store — how the hybrid batch lane feeds the real-time lane.
- Dynamic Batching — how real-time claws back throughput inside the red lane.
- Caching Strategies — where precomputed batch answers live for cheap lookup.
- Data Drift and Staleness — the veto that overrides a winning cost argument.
- Autoscaling & Model Serving — the infra whose idle cost is the overhead .