Single logo
  • Courses
  • Blog
  • About
Join for freeJoin free
Learning pathServe a Model in Production: Docker, Latency and Scaling
  1. 1
    Online, Batch or Streaming? Picking the Serving Pattern for an ML Model
  2. 2
    A Production FastAPI for an ML Model: Input Limits, /health, /ready and a Model Version
  3. 3
    Batch Scoring a Million Rows: Chunks, a Run ID and a Safe Rerun
  4. 4
    Docker Essentials for ML: Images, Containers and Volumes with a Model API
  5. 5
    Containerising a Model API: A Dockerfile for FastAPI and scikit-learn, Line by Line
  6. 6
    Latency Math: p50, p95, p99 and Why the Tail Reaches Your Users
  7. 7
    Measuring Latency of an ML API: Timing Inside with OpenTelemetry, Outside with a Load Test and Locust
  8. 8
    Making ML Inference Fast: ONNX, Micro-Batching and Quantisation, Measured
  9. 9
    Sizing and Autoscaling an Inference Service: From One Replica to a Replica Count
  1. Blog
  2. /
  3. Machine Learning
  4. /
  5. MLOps and Production ML

Learning path: Serve a Model in Production: Docker, Latency and Scaling · Step 1 of 9

Online, Batch or Streaming? Picking the Serving Pattern for an ML Model

Before writing any API code, decide how a model's answers should reach people. Two questions, who is waiting and when is the input known, pick between an online API, batch scoring and streaming.

Chaand Sheikh

·27 November 2026Serving Models

What you will learn

  • Tell online, batch and streaming serving apart
  • Pick a pattern with two questions: who is waiting, and when is the input known
  • Name what each pattern costs to run
  • Place real cases, including mixed ones, in the right pattern

Before you start

  • Deploy a Machine Learning Model with FastAPI

The model is trained and saved. Now, how should its answers reach people? It's tempting to start writing an API straight away, but pick the serving pattern first. There are three, and two small questions decide between them.

Three kitchens

Think of three kitchens serving the same food.

  • Cook to order. An order comes in, the cook makes it right then, and the plate goes straight back out. Somebody is always waiting for each plate. That's an online API.
  • Meal-prep Sunday. You cook once, store the lunches in the fridge, and during the week a lunch is just taken out. Nobody waits, because it's ready when you ask. That's batch scoring.
  • A conveyor-belt sushi bar. The plates never stop moving, and people pick the ones they want as they pass. That's streaming.

Same food, three very different ways of serving it.

Two questions pick the pattern

  1. Is someone waiting for the answer?
  2. If yes: how does the input arrive? One request at a time, when a person asks, means online. Events that keep flowing, one after another, means streaming.
  3. If nobody is waiting: when is the input known? If it's known ahead of time, score the whole table on a schedule. That's batch.
Who is waiting, and when is the input known Is someone waiting? yes no How does the input arrive? Input known ahead of time one request keeps flowing Online Streaming Batch
Answer two questions, and the pattern usually picks itself.

Online: one request in, one answer out

Three people, Anna, Ben and Chloe, each send their inputs to the rain API and wait for an answer. Every one of them is waiting while the model runs.

What does that cost you? The service must be always running, it must answer quickly, and it must handle spikes when many people ask at once. The rain API from Deploy a Machine Learning Model with FastAPI is an online service, and A Production FastAPI for a Model makes it ready for real traffic.

Batch: score everything ahead of time

Take a table of towns where every input is known. A scoring job runs on a schedule, say every night. It loads the model once and goes through the rows: Leeds is rain, Bath is dry, and so on. Each answer is saved into a predictions table. (The towns are just an example.)

Later, when the rain app needs Bath, it simply looks the answer up. No model runs at that moment, so the answer is instant.

The catch: if a new town, say Newtown, shows up after the job has run, it has no answer yet. It waits for the next run. So batch answers are fast and cheap, but they can be a little old. Batch Scoring builds such a job on a million rows.

Streaming: events keep coming

Think of sensors on a machine that send readings all day. Each reading flows into a scorer, which scores it as it arrives. Normal readings go to a log, and nothing else happens. When one looks wrong, an alert goes out right away. Nobody asked; the model simply reacted.

Often one reading isn't enough, so the scorer keeps a small window of the last few readings, and that window slides along as new ones arrive. Streaming gives you quick reactions, but you also need a place for events to flow, and some memory of the recent past.

Five cases, three lanes

CaseWho waits? When is the input known?Pattern
Approving a card payment at the tillA person is waiting; the input arrives with the requestOnline
A rain forecast for every town each morningEvery input is known the night beforeBatch
A weekly list of customers likely to leaveThe team reads it on a scheduleBatch
A machine sensor that starts to look wrongReadings never stop; an alert should be quickStreaming
Home-page picks for each shopperComputed ahead, looked up when the page loadsBatch, with a small online part

The last one shows that many real systems mix patterns.

Climb a step only when the need forces you

Think of the patterns as steps on a staircase:

  • Batch is the bottom step. It's a scheduled job, and if it fails, you rerun it. Start here.
  • Online is higher. You need a server that's always up, fast answers, and a way to scale with traffic.
  • Streaming is the top step. Everything online needs, plus a stream platform and memory of recent events.

Rule of thumb: if nobody is waiting, start with batch. This is advice, not a statistic. The Google Cloud documentation for Vertex AI makes the same split: online inference when requests answer application input, batch inference when you don't need an immediate response.

The simplest pattern that meets the need is the right one.

Common mistakes

  • Building an API by default. If the inputs are known the night before, an always-on server is cost and risk you don't need.
  • Forgetting that batch answers age. A row that arrives after the run has no answer until the next run.
  • Calling anything fast "streaming". Streaming means events keep flowing in and the model reacts without being asked. A quick API is still online.
  • Forcing one pattern on a mixed system. Compute ahead where you can, look up online where you must.

Quick recap

PatternWho is waitingWhat it costs
OnlineA person, for each requestAlways up, fast, handles spikes
BatchNobody; answers are looked up laterA scheduled job; answers can be a little old
StreamingNobody asks; the model reacts to eventsA stream platform and a window of recent events

Try it yourself

Pick one model you know, from a course or from life. Ask who is waiting, and when the input is known. Then name its pattern.

Built this? Share your solution in the StudyEasy AI Community.

Join free on Skool →
Next →
A Production FastAPI for an ML Model: Input Limits, /health, /ready and a Model Version
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Related articles
Python Virtual Environments: One Project, One Toolbox

Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.

Git and GitHub Fundamentals: Commits, Branches, Push and Pull

The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.

Testing a FastAPI App with pytest: Three Small Tests

A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.

Config and Logging Instead of Hard-Coded Values in ML Training

Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.

On this page
  • Three kitchens
  • Two questions pick the pattern
  • Online: one request in, one answer out
  • Batch: score everything ahead of time
  • Streaming: events keep coming
  • Five cases, three lanes
  • Climb a step only when the need forces you
  • Common mistakes
  • Quick recap
  • Try it yourself
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.