← Back to Index

6. Batch vs Real-Time Systems

Batch ML Systems

Batch systems process data in scheduled intervals. All predictions are pre-computed and stored.

AspectBatch
FrequencyHourly, daily, weekly
LatencyMinutes to hours
ComputeSpark, Airflow, scheduled jobs
StoragePre-computed predictions in DB or cache
Use casesDaily recommendations, churn predictions, credit scoring
# Batch ML pipeline (daily)
At 2 AM:
  1. Load yesterday's features (offline store)
  2. Load ground truth for evaluation
  3. Retrain model if drift detected or scheduled
  4. Batch predict for all active users
  5. Write predictions to predictions table
  6. Applications read pre-computed predictions

Real-Time ML Systems

Real-time systems make predictions on-demand with sub-second latency.

AspectReal-Time
TriggerRequest-driven (user action, API call)
LatencyMilliseconds to seconds
ComputeInference servers (Triton, TorchServe, vLLM)
StorageOnline feature store (Redis), prediction cache
Use casesFraud detection, real-time recommendations, ad serving

Lambda Architecture

Processes data through both batch (comprehensive, high latency) and speed (approximate, low latency) layers, merging results in the serving layer.

Kappa Architecture

Everything is treated as a stream. Batch is replayed stream processing. Simpler infrastructure but requires robust stream processing (Kafka + Flink).

Choosing Your Approach

ScenarioRecommendation
You need instant predictions (fraud, ads)Real-time
Predictions can be pre-computed (daily feed)Batch
Mix of historical and real-time dataLambda
Simple pipeline, stream-native teamKappa
Exercise: A music streaming app needs two ML features: a) a daily "Discover Weekly" playlist for each user, b) a "Next Song" recommendation that updates instantly based on the current song and user behavior. Design the system — which features use batch, which use real-time, and how do they share infrastructure (feature store, model registry)?