5.3.7 · D3MLOps & Deployment

Worked examples — Batch vs real-time inference

3,937 words18 min readBack to topic

Before anything, let me re-anchor every symbol so you never have to scroll up:


The scenario matrix

Every situation this topic throws at you falls into one of these cells. The examples below are labelled with the cell they cover.

Cell Axis / edge case Governing quantity
A Huge slack, high slack large and → batch
B Input born at the deadline (no earlier tick) precompute infeasible → real-time forced
C Large slack but low cost rule fails
D Break-even boundary () tie-breaker (staleness/latency)
E Degenerate: (overhead-free) threshold
F Degenerate: (huge warm-up) threshold
G Limiting: infinite input space can't precompute at all
H Hybrid split by "what changes slowly" pipeline decomposition
I Throughput vs latency numeric trade Dynamic Batching + queue stability
J Exam twist: staleness beats cost slack large but answer decays ()

We now walk one example per cell. Every number is machine-checked at the bottom.


The decision flow (walk it in words, then the figure)

Here is the logic in plain words, so you can follow it even without the picture:

  1. Start the moment the input arrives at .
  2. Gate 1 — feasibility: Does the input exist early enough to work ahead — i.e. is there a batch window before the deadline in which the input already exists? If no (the input only appears at the deadline itself), take the red forced path straight to real-time — no cost math is possible, because you cannot compute something that hasn't happened yet.
  3. If yes, drop to Gate 2 — economics: Is and is staleness tolerable ()? If yesbatch. If noreal-time.

Figure s01 — Decision flow (described in full so it stands alone). A top black box "input arrives ()" feeds down into Gate 1 ("input exists early?"). From Gate 1 a red arrow labelled NO drops to a red box "REAL-TIME (forced)" — this is the fast exit when precompute is infeasible. A "YES" arrow from Gate 1 goes right into Gate 2 ("?"), which splits into "no → REAL-TIME" and "yes → BATCH". Trace the red arrow first: it is the only path that skips all cost arithmetic.

Figure — Batch vs real-time inference

The examples




Let's see the break-even geometry — it's the crossing point of two cost curves.

Figure s02 — Break-even curves (described so it stands alone). Horizontal axis is utilization ( to ); vertical axis is cost per useful prediction ($). The red curve is , shooting toward infinity as (you waste almost everything). The dashed black horizontal line is the flat . A red dot marks their crossing at : to the left batch is dearer → real-time wins; to the right batch is cheaper → batch wins.

Figure — Batch vs real-time inference





Picture the trade-off directly:

Figure s03 — Throughput vs latency (described so it stands alone). Horizontal axis lists the two serving modes; vertical axis is throughput (predictions/second). A short black bar marks "one-at-a-time" (/s) and a tall red bar marks "dynamic batch (32)" (/s). Each bar is annotated with its per-request latency ( ms vs ms), so the tall red throughput bar visibly carries the higher latency label — the trade made explicit.

Figure — Batch vs real-time inference


Recall

Recall The whole matrix in one breath

Precompute infeasible (input born at deadline, no window ) ::: real-time forced (Cell B/G). Feasible, high , staleness OK () ::: batch (Cell A). Feasible, low below threshold ::: real-time (Cell C). exactly ::: strict "" false → costs equal → decide by staleness/latency (Cell D). ::: threshold , real-time always wins on cost (Cell E). ::: threshold , batch almost always wins (Cell F). Cost says batch but and penalty dominates ::: real-time anyway (Cell J). Expensive-stable + cheap-live ::: hybrid split (Cell H). Batching at high RPS ::: check service rate arrival rate for queue stability (Cell I).


Connections

  • Parent — Batch vs real-time inference
  • Model Serving — hosts the real-time endpoints in Cells B, C, G, I, J.
  • Feature Store — serves the batched embeddings of Cell H to live models.
  • Latency and Throughput — the trade quantified in Cell I.
  • Dynamic Batching — the compromise of Cell I.
  • Autoscaling — adds replicas for queue stability (Cell I) and absorbs overhead .
  • Data Drift and Staleness — the override force with penalty in Cell J.
  • Caching Strategies — how batch results in Cells A/H are stored and looked up.