Skip to the workspace
Pebellslearn by building
Tracking, Orchestration and Deployment  ›  Capstone Project

Serving Models: Batch and Online

Model Training & Serving 15 minA model is served either in batch, scoring many rows on a schedule, or online, answering single requests behind an API, and new versions are released gradually so a bad one can be caught.

mlops / Serving Models: Batch and Online

Explore each scene at your own pace.

01 · The rule

The rule

Serving Models: Batch and Online

Tunebox wants two things from the churn model. The retention team emails at-risk subscribers every Monday. The app wants to show a "we'll miss you" offer the instant someone opens the cancel page. Same model, two very different ways of serving it.

The rule

Ask when the answer is needed: later for many, now for one.

Batch serving scores many rows on a schedule and stores the results. A job runs on Sunday night, loads models:/churn-model@champion, scores every active subscriber and writes the scores to a table. The Monday email reads that table.

  • Simple, cheap, easy to retry.
  • Predictions can be up to a week old.

Online serving answers one request at a time, behind an API, in milliseconds:

from fastapi import FastAPI
import mlflow, pandas as pd

app = FastAPI()
model = mlflow.pyfunc.load_model("models:/churn-model@champion")

@app.post("/predict")
def predict(features: dict) -> dict:
    risk = model.predict(pd.DataFrame([features]))[0]
    return {"churn_risk": float(risk)}
  • Fresh answers using the latest behaviour.
  • Must stay up and fast, so it needs monitoring, several replicas and a latency budget.

Both share one danger: training-serving skew, where features are computed differently at serving time than in training. The cure is to use the same feature code in both places.

Releasing a new version safely usually goes in stages:

  1. Shadow — the new model scores real requests, but its answers are only logged, never used.
  2. Canary — it serves a small slice, say 10%, of real traffic while the rest stays on the champion.
  3. Full rollout — if error rate, latency and business metrics hold, it takes all traffic. If not, roll back by moving the registry alias.
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.