Batch Scoring vs Real-Time Inference
Choose offline batch jobs vs low-latency online scoring based on product needs.
In plain words
Batch scoring answers many questions at once on a schedule and saves the answers. Real-time scoring answers one question the moment someone asks.
Think of it like…
A newspaper versus a live broadcast. The paper (batch) is prepared once for everyone and delivered cheaply at a fixed time; the live broadcast (real time) reacts to events as they happen but needs a studio staffed around the clock.
Where you’ve seen it
A telecom wants churn scores for 20 million customers. The retention team contacts customers the next morning, so a nightly batch fits: the job reads the latest feature snapshot, scores in vectorised chunks at about 50,000 rows a second and finishes in 20,000,000 / 50,000 = 400 seconds, about 7 minutes. Results (20 million rows of customer_id, score, model_version, scored_at, roughly 16 bytes each, 320 MB) are written to a partitioned table and loaded into the CRM. Compute is one instance for roughly 0.12 hours a day. The alternative, a real-time API serving 400 requests a second at peak with 8 ms of CPU per request, needs about 5 instances running all day, 5 × 24 = 120 instance-hours a day, about 1,000 times the batch compute for the same business outcome, plus a low-latency feature store, autoscaling and on-call. Scores are at most 24 hours old (about 12 hours on average), which is acceptable for retention calls but not for fraud scoring at checkout, where the decision must use the current transaction and must complete in under 100 ms: that model is served online with features from an online store. A hybrid fits the recommendations product: embeddings and candidate lists are precomputed in batch, and a light real-time ranker combines them with the user's last five clicks. Operational details differ: batch needs idempotent, partitioned runs (a rerun for 2026-11-20 overwrites that partition), backfills, data quality checks (row count within 2% of yesterday, null rate of scores near zero), a published schedule and alerts when the job is late; online needs health checks, autoscaling, latency SLOs, validation and fallbacks. Both log the model version with every prediction so results can be traced and compared.
Words you’ll hear
- Batch scoring
- Scoring many records on a schedule and storing the results.
- Online inference
- Scoring a request on demand with low latency.
- Staleness
- How old a prediction is when it is used.
- Micro-batch / streaming
- Scoring small groups of events continuously as they arrive.
Visual diagram
Theory & deep dive
Choosing by freshness, latency, volume and cost
Start with the decision: when is it made, what information must it use, and what does a late or stale prediction cost? If the action happens on a schedule (a morning call list, a weekly campaign, a nightly risk report) and inputs change slowly, batch is almost always right. If the decision occurs inside a user interaction (checkout, search, a chat reply) and depends on information that exists only at that moment, you need online inference. Volume matters in the other direction: scoring all 20 million customers online just to use a fraction of the scores is wasteful, while scoring one customer per request at 400 requests a second needs a proper service.
Cost follows utilisation. A batch job that scores 20 million rows at 50,000 rows a second runs 400 seconds (about 7 minutes) and uses about 0.12 instance-hours a day. A real-time service sized for 400 requests a second at 8 ms of CPU each needs 3.2 busy cores, so about 5 instances at a 70% target, running 24 hours: 120 instance-hours a day, roughly 1,000 times as much, because the capacity must exist even when traffic is low. Add the hidden costs of online: low-latency features, autoscaling, high availability and on-call. Add the hidden costs of batch: staleness (at most 24 hours, 12 on average here), a schedule that can fail silently and large write volumes.
Batch: 20,000,000 rows ÷ 50,000 rows/s = 400 s ≈ 6.7 min ≈ 0.12 instance-hours/day. Online: 400 req/s × 8 ms = 3.2 cores → 5 instances × 24 h = 120 instance-hours/day. Ratio ≈ 1,000 to 1 for the same next-morning retention list.
Designing each path, and hybrids
Batch design: read a consistent snapshot of features, score in vectorised chunks, write results to a partitioned table keyed by (customer_id, scoring_date) with model_version and scored_at, and make runs idempotent (rerunning a date overwrites its partition) and backfillable. Add data checks (input row count within a few percent of yesterday, null and range checks on scores, distribution comparison with the previous run) and alert when the job is late or fails. Downstream systems read a table or key-value store, so decide how consumers handle missing or stale scores. Online design: validate inputs, load the model once, keep p95 within the latency SLO, fetch features from an online store, provide fallbacks (a rule or the last batch score) when dependencies fail and monitor latency, errors and prediction drift.
Hybrids are common and effective: precompute expensive or slowly changing parts in batch (embeddings, candidate lists, risk tiers) and apply a cheap real-time model that incorporates fresh context (the last few actions, the current basket). Streaming or micro-batch scoring suits near-real-time needs (scores refreshed every minute) without the full cost of per-request serving. Whichever you choose, keep one model definition and feature logic for both paths to avoid skew, log the model version with every prediction and compare batch and online outputs on a sample to confirm they agree. Revisit the choice when the business changes: a campaign that moves from weekly to in-session offers changes the serving requirement.
Run for 2026-11-20: input rows 20,013,442 (yesterday 19,987,100 → +0.13% ✓). Scores null rate 0.00% ✓. Mean score 0.151 vs 0.149 yesterday ✓. Output partition scoring_date=2026-11-20, model_version churn-v12, finished 02:07 (SLA 06:00) ✓.
How it works, step by step
Step 1 of 41. Define the decision
State when the prediction is used, what inputs it needs and the cost of delay or staleness.
- Ask
- how stale is too stale?
When to use it & trade-offs
What it is
There are two basic ways to put a model to work. Batch scoring runs the model over a large set of records on a schedule (nightly, hourly) and writes the predictions to a table or key-value store for other systems to read. Real-time (online) inference runs the model when a request arrives and returns a prediction in milliseconds to seconds. A middle path, near-real-time or streaming scoring, scores events as they arrive in micro-batches. The choice depends on how fresh the inputs must be, how quickly the decision is needed, how many predictions are required, cost and operational complexity. Many systems combine them: precompute expensive scores in batch and adjust or re-rank with real-time signals at request time.
Why it matters: Teams often default to a real-time API because it feels modern, then pay for servers that idle all day, build feature pipelines that must be fast and fresh and carry an on-call burden, when a nightly job would have met the business need. The reverse mistake is scoring a fraud model once a day when the decision happens at checkout. Matching the serving pattern to the decision's timing and value avoids both wasted money and wasted opportunity.
When to reach for it
- Batch for churn lists, credit refreshes and weekly campaigns
- Real time for fraud at checkout, search ranking and chat
- Hybrids where candidates are precomputed and re-ranked live
When to avoid or be careful
- A real-time API for decisions made once a day
- Daily scores for decisions made at transaction time
- Batch jobs with no idempotency or data checks
Serving patterns
Strengths: Cheap; simple; easy to monitor and backfill.
Watch out: Stale predictions; no per-request context.
Strengths: Fresh inputs; immediate response.
Watch out: Always-on cost; strict latency and reliability needs.
Strengths: Fresher than nightly without per-request serving.
Watch out: More moving parts than batch.
Interview signals & numbers to know
When this topic comes up
- “Batch or real time for this use case?”
- Cost comparison by instance-hours
- Staleness and freshness requirements
- Idempotent, backfillable batch jobs
- Hybrid precompute plus live re-ranking
Benchmarks & rules of thumb
- 400 s
- 20M rows at 50,000 rows/s
- ≈ 1,000×
- ratio of real-time to batch instance-hours in the example
- ≤ 24 h (avg 12 h)
- staleness of nightly scores
Common mistakes & follow-ups
Common interview mistakes
- Defaulting to an API without asking when the decision happens.
- Letting batch scores silently go stale when a job fails.
- Implementing different feature logic for batch and online.
Likely interviewer follow-ups
- How would you support a campaign that needs hourly scores?
- How do you monitor a nightly scoring job?
- How would you keep batch and online predictions consistent?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Batch Scoring vs Real-Time Inference with data science interview Q&A and hands-on practice.