Choose when and how predictions must arrive
Training creates a model artifact; inference uses that artifact to produce predictions. The correct inference architecture depends first on when predictions are needed: in bulk by a deadline, during one waiting request, or continuously as events arrive.
Serving mode is separate from learning mode. A model may retrain weekly yet serve online every millisecond, or retrain daily and write one batch of scores nightly.
What You Will Be Able to Explain
- Compare batch, online, and streaming inference
- Separate training and inference pipelines
- Distinguish synchronous and asynchronous prediction
- Calculate throughput and completion time
- Allocate an end-to-end latency budget
Latency, throughput and serving modes
These terms name different responsibilities. Read the meaning before following them through the diagrams and worked example.
Core vocabulary
Serving architecture follows the timing contract
Batch inference reads a bounded input, partitions it across workers, writes versioned outputs, and records which partitions succeeded. It suits overnight churn scoring because the business needs all scores by morning, not one response per waiting user.
Online inference usually sits behind an API. It validates one request, obtains fresh features, runs the model, applies decision logic, and responds within a stated latency target. Every synchronous dependency consumes the same end-to-end budget.
Streaming inference consumes an unbounded event stream. It may maintain state such as counts over a time window, track offsets, checkpoint progress, and write predictions continuously. Streaming is not simply a very frequent batch job; recovery and event ordering are explicit concerns.
Batch, online, and streaming inference solve different timing problems
When is a prediction needed, and how does that shape the architecture?
Choose an inference mode from the operating need
Package the model with the code it depends on
A deployable inference unit combines the trained model artifact, its preprocessing or feature contract, compatible runtime dependencies, and the serving code and configuration. Packaging these pieces together makes dependency versions repeatable, prevents model/runtime incompatibility, and lets a release or rollback restore one known bundle. A container is one common packaging mechanism for keeping that environment consistent, but containers are not mandatory for every architecture and containerization is not the definition of MLOps.
Training and inference pipelines have different outputs
Account for waiting time as well as model compute
Queues allow asynchronous callers and absorb short bursts, but they do not create capacity. When arrival rate remains above processing rate, queue depth and waiting time keep growing. Backpressure slows or rejects producers before overload becomes uncontrolled.
An online response spends one shared latency budget
Which sequential stages consume a 100 ms service target?
Worked Example: Estimate a 10-million-row batch
Given: There are 10,000,000 predictions. Average model compute is 4 ms = 0.004 seconds per prediction. Assume 20 workers are identical, perfectly utilized, and work divides evenly. Ignore data loading, network, startup, writing, failures, and coordination.
- Sequential compute = 10,000,000 × 0.004 seconds = 40,000 seconds.
- With 20 perfectly utilized parallel workers, ideal wall time = 40,000 ÷ 20 = 2,000 seconds.
- Convert seconds: 2,000 ÷ 60 = 33.333... minutes, or approximately 33 minutes 20 seconds.
- This is an optimistic compute-only lower bound. Real elapsed time adds input/output, startup, skewed partitions, retries, and spare capacity.
- An online 100 ms SLA asks a different question: one request's complete dependency chain must finish within 0.100 seconds. A high-throughput batch worker that waits to fill large batches may violate that per-request target.
Result and interpretation: The toy batch can finish model compute in about 33 minutes 20 seconds under ideal assumptions. The same design is not automatically appropriate for an online endpoint because bulk throughput and individual latency optimize different goals.
Calculate serving capacity and describe the inference contract
The label above each block states what it is. Runnable Python can be executed as shown with the standard library; pseudocode and configuration communicate architecture and require adaptation to a real platform.
Score batch partitions with restartable outputs
Each partition records input, model, feature, and output versions so a failed partition can be retried without rescoring successful work.
for partition in uncompleted_partitions(run_id):
rows = read_snapshot(input_version, partition)
features = transform(rows, feature_version)
scores = model.predict(features)
write_atomic(run_id, partition, scores, model_version)
mark_complete(run_id, partition)Make the online contract explicit
The total is an application target allocated across dependencies. Teams measure actual percentiles and revise these budgets.
endpoint: POST /v1/churn-score
total_sla_ms: 100
timeouts_ms:
feature_lookup: 30
model_inference: 40
total_internal: 90
fallback: manual_review
log_versions: [request_schema, features, model, policy]Choose a serving mode from the response deadline
- Use the least complex mode that satisfies prediction freshness and response timing.
- Keep work asynchronous when no user or transaction must wait for it.
- Measure p50, p95, and p99 latency; an average can hide slow requests that violate the experience.
- Plan overload behaviour—queue, shed, degrade, or scale—before traffic exceeds capacity.
Failure Analysis and Recovery
Observed failure → likely cause → controlled response
Connect to Earlier Lessons
- Batch versus online learning
Do not confuse update cadence with inference serving mode.
- Efficient LLM serving
See token-generation-specific serving techniques.
- GenAI deployment
Compare hosted and self-hosted generative application serving.
Summary / Key Takeaways
- Training produces an evaluated artifact; inference applies an approved artifact to current inputs.
- Batch inference optimizes bulk completion by a deadline, online inference optimizes waiting-request latency, and streaming inference continuously handles events and state.
- Synchronous callers wait for a result; asynchronous work can be queued and completed later.
- Latency measures elapsed response time, while throughput measures completed predictions per unit time.
- Twenty ideal workers reduce 40,000 seconds of compute to 2,000 seconds—about 33 minutes 20 seconds—under deliberately simplified assumptions.
- A 100 ms online SLA covers validation, feature lookup, inference, policy, network, and serialization, not only model compute.
- Queues absorb temporary bursts but sustained overload requires backpressure, scaling, reduced work, or controlled rejection.