When should you choose batch (offline, precomputed) inference over online (real-time) inference, and how do hybrid designs combine the two?
ML system design, Serving
Level L2 Elementary. Length Short. Nature Th Theoretical.
What's being asked
Whether you can match serving architecture to product latency, freshness, input space and cost rather than defaulting to live GPU (graphics processing unit) serving.
Key idea
Batch inference precomputes predictions on a schedule and stores them for fast lookup, trading freshness for simplicity and throughput. Online inference computes predictions on demand inside the request path when fresh session context or an unbounded input space makes precomputation impossible, while large-scale systems often combine both in a hybrid pipeline.
Steps
- Contrast the two modes: batch inference scores entities periodically (for instance nightly or hourly) and writes results to a key-value store or cache, whereas online inference runs the model live on every incoming request.
- Choose batch inference when inputs are bounded and freshness can lag: if you score a fixed list of customers for churn emails or compute daily homepage lists, batch jobs give very fast reads (a key-value lookup) at serving time and simple horizontal scaling.
- Check the batch trade-offs: precomputing for every user wastes compute if only of users visit that day, and predictions become stale between batch runs.
- Choose online inference when real-time context or unbounded inputs matter: live search queries, fraud checks at checkout, and recommendations reacting to the user's last three clicks cannot be precomputed ahead of time, even though online serving costs more engineering effort to meet tight latency and skew constraints.
- Use a hybrid design for scale: precompute item embeddings, user profiles and coarse candidate sets in batch, then run a lightweight online ranker over those candidates using fresh real-time features when the user arrives.
Common mistakes
- Building a complex real-time model service when periodic batch predictions in a lookup table would satisfy product requirements.
- Ignoring wasted batch compute when only a small fraction of stored entities is ever queried before the next refresh.
- Forgetting that online inference needs low-latency feature access and strict consistency with training preprocessing.
How long your answer should be
About 2 minutes covering the trade-offs and one hybrid example.
Read this
Previous in ML system design: An ML service has 100 million daily active users, and each user triggers 20 model requests per day. Peak traffic is the daily average, and one server handles 500 QPS (queries per second) within the latency target. What are the average QPS, peak QPS, minimum servers needed, and servers needed with 30% headroom? Why do you size for peak rather than average?
Next in ML system design: What is a feature store, what problems does it solve in production ML, and when is it unnecessary?