When the input becomes available (arrival time ta).
When the prediction is actually needed (deadline td).
Define the slack:
slack=td−ta
If slack is large (you know the input long before you need the answer) → precompute in batch. Nothing is wasted by doing it early... unless the answer goes stale.
If slack is tiny (input arrives the instant you need the answer) → you must serve real-time; there's no earlier moment to precompute.
u = fraction of predictions actually used by a consumer.
Batch cost per useful prediction, if you predict for allN candidates but only uN get used:
Cbatch=u⋅NN⋅c=uc
Why this step? You pay Nc to compute everything, but only uN predictions do work, so cost is spread over the useful ones. If u is small (you precompute for users who never log in), batch is wasteful.
Real-time cost per useful prediction — you only compute when asked, so u≈1:
Crt=c+o
where o is the per-request overhead (network, serialization, keeping a warm server idle).
Break-even: batch wins when
uc<c+o⟺u1<1+co⟺u>c+oc
Why this matters: low overhead o (small co) pushes the threshold near 1 → real-time is cheap → lean real-time. High utilization near 1 with expensive models → batch precompute and cache.
Batch systems group inputs to use vectorized/GPU parallelism, maximizing throughput but adding wait-to-fill-a-batch latency. Real-time can use dynamic batching (wait a few ms to collect concurrent requests) as a compromise — the middle ground.
What single quantity best decides batch vs real-time?
The slack td−ta: how long before the deadline the input is known. Zero slack forces real-time.
Define batch inference.
Predicting on a large accumulated set on a schedule, storing results for later lookup (offline).
Define real-time inference.
Computing a prediction synchronously on request arrival within a tight latency budget (online/on-demand).
Why is "real-time = batch with batch size 1" wrong?
The model math is identical but real-time requires live serving infra: autoscaling, load balancing, p99 SLAs, cold-start handling.
Batch cost per useful prediction if only fraction u are used?
c/u — total compute Nc divided over the uN predictions actually consumed.
When does batch beat real-time on cost?
When utilization u>c+oc, i.e. utilization exceeds the ratio of compute to compute-plus-overhead.
Latency vs throughput?
Latency = time for one request; throughput = predictions per second. Real-time optimizes latency, batch optimizes throughput.
What is dynamic batching?
Real-time servers briefly wait (few ms) to group concurrent requests, trading a little latency for much higher throughput.
Batch's fundamental weakness?
Staleness — predictions computed early may be outdated by the time they're used.
Why can't you always precompute?
The input (feature combination) may not exist until the live event happens (e.g. this exact transaction), and the input space can be effectively infinite.
Recall Feynman: explain to a 12-year-old
Imagine making sandwiches. Batch = you make 100 sandwiches early in the morning and put them in the fridge, so lunchtime is fast — but a sandwich might get soggy (stale!) and some never get eaten (wasted). Real-time = you make each sandwich the moment someone orders it — always fresh, nothing wasted, but the person has to wait and you need a cook standing by all day. If you know exactly what everyone wants ahead of time and they'll all eat → make them early (batch). If every order is a surprise you can't guess → make on the spot (real-time).
Dekho, inference ka matlab hai trained model se prediction lena. Sawaal sirf ek hai: prediction abhi ek-ek karke chahiye (real-time) ya baad me, saath me bahut saare chahiye (batch)? Iska decide karne ka sabse simple tarika hai slack — yaani input aane ka time aur answer chahiye hone ka time, dono ke beech ka gap. Agar gap bada hai (jaise Netflix recommendations — raat ko bana lo, subah dikha do) to batch me pehle se compute karke store kar lo. Agar gap zero hai (jaise card swipe pe fraud check — transaction abhi hui, jawab abhi chahiye) to real-time hi karna padega, kyunki jo input abhi tak exist hi nahi karta usko pehle se compute kaise karoge?
Cost ka funda bhi seedha hai. Batch me tum sabke liye predict kar dete ho, par sab log use nahi karte — agar sirf fraction u log use karte hain to real cost c/u ho jaata hai (wasted compute). Real-time me sirf jab request aati hai tabhi compute hota hai, par har request pe thoda overhead o lagta hai (server chalu rakhna, network waghera). Break-even tab hota hai jab u>c/(c+o) — matlab agar utilization high hai to batch sasta, warna real-time sasta.
Ek important cheez: staleness. Batch prediction raat ko bani, shaam ko use hui — beech me duniya badal gayi to answer purana pad jaata hai. Ye batch ki weakness hai. Real-time hamesha fresh hota hai par server hamesha ready rakhna padta hai — ye uski cost hai. Aur real production me mostly hybrid hi hota hai: heavy aur slow-changing part (jaise document embeddings) batch me, aur query-specific fresh part (jaise is query ka matching) real-time me. Yaad rakho: BATCH = Bulk, Ahead of time, Cached, but stale; REAL = Right now, Each request, Alive server, Low slack.