Serving models: batch and online

ExplainedMLOpsDevOps, Hands OnBy Cloud Hands On

The two ways to put a model to work, and how to choose between them.

Batch serving scores many records on a schedule and writes the results somewhere: tonight's orders, this month's invoices. It's cheap, easy to re-run and easy to check before anyone uses the results.

Online serving answers one request at a time through a web endpoint, for decisions that can't wait, such as a checkout. It needs a server running all the time, health checks, scaling, timeouts and a plan for what the app does if the model is slow or down.

Either way, load the model by registry alias and record the model version next to each prediction. Start with batch unless a person or system truly needs the answer within seconds.

Cost. Free locally. In the cloud, batch jobs cost only while running; online endpoints cost every hour they exist.

Use it when

How it works

Batch
Scheduled job: read records, score, write results with the version.
Online
Endpoint: /ping for health, /invocations for predictions.
Both
Load by alias; log the model version.

Options

Batch first
Cheapest and simplest when answers can wait hours.
Online
When the answer is needed in the moment.
Both
Online for live decisions, batch for everything else.

Example. SS Kaiser scores all next-day orders in a 6 pm batch and only calls an online endpoint for baskets at the checkout. The endpoint runs two small copies; the batch costs a few minutes of compute a day.

Don't confuse it with

Batch
Many records, on a schedule, cheap.
Online
One request, in milliseconds, always running.

Words to know

Batch scoring
Scoring a file or table of records in one go.
Online endpoint
A web address that answers predictions on request.
Latency
How long one prediction takes to return.

Where to look

  1. batch_score.py
  2. mlflow models serve

Practise it

Read it in the guide, next to the tasks and labs.

Open in DevOps, Hands On

Keep going