Inference Modes

Batch, online and streaming inference, how to choose between them from freshness, latency and volume, the serving architecture, batching, and CPU against GPU.

Batch Inference
▶ lab

Dataset → Model → Predictions, on a schedule. When the prediction can be precomputed, batch is the cheapest and most debuggable mode — and the staleness window is a property to design, not a defect.

Q · The product needs a prediction for every customer, but not right now. When can predictions be computed ahead of time, and what does the delay between scoring and use cost?
Online Inference
▶ lab

Request → Features → Model → Prediction → Response, inside a latency budget. The feature fetch is usually the latency, and the timeout and fallback are part of the model's quality, not an infrastructure detail.

Q · A prediction is needed inside a request that a user is waiting on. Where does the time go, and what is served when the model cannot answer in time?
Streaming Inference
▶ lab

Continuous events drive predictions: the model sits inside a stream processor, features are state kept per key, and ordering, late events and where the model sits in the topology decide correctness more than the weights do.

Q · Events arrive continuously and every one may change a prediction. When does the model belong inside the stream rather than behind an endpoint or in a nightly job — and what does the stream's semantics do to the prediction?
Choosing the Inference Mode
▶ lab

How fresh must the prediction be, can it be precomputed, does it need live features, what is the latency budget, what is the volume — those five questions decide batch, online, streaming or hybrid. Online is often unnecessary, and the churn case shows why.

Q · Before drawing the serving architecture: which questions decide whether predictions are computed in a nightly job, on request, on every event, or some combination?
Model Serving Architecture
▶ lab

Client → Backend → Model Service → Artifact → Prediction. Where preprocessing runs, model-in-process against model-as-service, versioned endpoints, warm-up and health checks — and the line where the Backend domain takes over.

Q · A prediction has to reach a user through a running system. Where does the model live, who owns the boxes around it, and what does the system have to do before a single request is safe to serve?
Inference Batching

Individual requests are grouped into a batch before the accelerator sees them. Throughput rises because the hardware runs one large matrix multiply instead of many small ones; latency rises because every request waits for the batch. Dynamic batching with a maximum wait is the knob.

Q · The accelerator is idle most of the time and the per-request cost is high. How does grouping requests change throughput and latency, and where is the trade-off set?
CPU or GPU for Inference

A workload decision: model size, available batch size, latency budget, cost per prediction and utilisation. A small tree model on CPU beats a GPU round-trip; a large transformer at volume does not fit on CPU. "GPU makes inference faster" is false as stated.

Q · The model is trained and needs hardware to serve it. Which questions decide whether an accelerator is worth its cost and its round-trip, and when does the CPU win outright?