Batch vs Real-Time Inference
Part of the Machine Learning Roadmap
In short
Does your prediction need to be ready in 100 ms while the user waits, or by tomorrow morning for a report? That one question shapes your whole serving setup.
Batch inference scores many records on a schedule, like nightly churn scores, while real-time inference answers one request at a time within milliseconds, like a fraud check during payment. The choice affects cost, latency and system design.

Think of it like this
Mess dinner vs the Maggi point
The hostel mess cooks dinner for 400 students at once at 7 pm: cheap and efficient, but you eat what's ready. The Maggi point outside makes one plate the moment you order. Batch inference is the mess, real-time inference is the Maggi point.
Watch it happen
Two ways to serve predictions
Batch
- Score millions of rows on a schedule
- Results saved to a table
- Cheap, minutes or hours of delay
Real-time
- One request, answer in milliseconds
- Model always running behind an API
- Fresh input, higher serving cost
Use batch when results can wait, like nightly churn scores. Use real-time when the user is waiting, like fraud checks at payment.
The big ideas
What you need to know
Batch = scheduled jobs
A job reads a whole table, predicts for every row and writes results back. Apps then just look up the saved answer.
Real-time = always on
A server keeps the model loaded and answers each request. Latency and uptime now matter a lot.
Freshness is the trade-off
Batch scores can be hours old. If the input changes every minute, like a cart, batch may be too stale.
Mix them
Many systems precompute heavy parts in batch and do a quick real-time step on top.
See it in code
Walk through the code
1import joblib2import pandas as pd3 4FEATURES = ["orders_30d", "days_since_last_order", "complaints_90d"]5model = joblib.load("churn_model.joblib")6 7df = pd.read_csv("customers_today.csv")8df["churn_risk"] = model.predict_proba(df[FEATURES])[:, 1]9df[["customer_id", "churn_risk"]].to_csv("churn_scores_today.csv", index=False)10print(f"Scored {len(df)} customers")1/3Same features and model as training, loaded once for the whole job.
A nightly batch job. A scheduler like cron or Airflow runs it, and the app just reads churn_scores_today.csv.
Save yourself the pain
Common mistakes
Oops
Building a real-time API for a dashboard that refreshes once a day.
Do this instead
If nobody waits for the answer, a batch job is cheaper and simpler.
Oops
Looping over rows and calling predict one by one in a batch job.
Do this instead
Predict on the whole DataFrame, or in large chunks. It can be many times faster.
Your mission
Same model, two modes
Quick check
A bank must decide in under a second whether a card payment looks like fraud. Which mode?
Go deeper
- 1List three ML features and decide whether each needs batch or real-time predictions.
- 2Write a batch script that scores a CSV and saves predictions with a timestamp.
- 3Measure the latency of a single prediction from your API.
Also part of these roadmaps
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.