Real-time vs batch data for AI applications: how to choose
Use batch data unless a decision loses value within minutes. Stream only those features, and look up live facts at question time with a tool call instead.
Use batch data for an AI application unless a decision loses its value within minutes. Stream only the few inputs that really have a freshness budget that short, such as recent payment attempts for a fraud check, and for facts that change constantly, such as order status or stock levels, have the model look them up from the source system at the moment it answers. Most AI features run well on data that is a few hours old, and the cost of streaming (late events, two code paths, harder testing) is only worth paying where staleness changes the answer.
Start with a freshness budget, not an architecture
Teams usually start with a technology choice, such as whether they need Kafka. That comes too early. The useful first question is per input: how old can this value be before the model's answer becomes wrong?
Google's Rules of Machine Learning put the model-level version of this bluntly in Rule #8: "How much does performance degrade if you have a model that is a day old? A week old? A quarter old?" The same question works one level down, per feature or per data source. A customer's lifetime order count can be a day old without anyone noticing. The number of card payments that customer attempted in the last ten minutes is useless if it is a day old, because its whole point is to catch a burst that is happening now.
So I would start with a spreadsheet: one row per input, with where it comes from, how often it really changes, and the oldest value you would accept. Most rows will say a day or an hour. The few that say seconds are your real-time requirement, usually a smaller set than the slide deck implied.
There is a second reason to write the budget down. Stale data rarely fails loudly. Rule #10 in the same guide warns that a model fed stale inputs "will adjust, and behavior will continue to be reasonably good, decaying gradually." Its example: Google Play once had a table that was stale for six months, and refreshing that table alone gave a 2% boost in install rate. A written freshness budget turns that silent decay into a check you can alert on, which is the same idea as the freshness checks in our article on data quality checks before launch.
Three ways to get data to a model
Batch processing runs over a finished set of records on a cycle, nightly or every fifteen minutes. It sees all the data for the period, joins freely, and if it fails you rerun it. Its weakness is age. A nightly job's output is up to a day old by the time it is used.
Stream processing handles events as they arrive and keeps running totals and windows up to date continuously. Its output is seconds old. But it never sees a finished dataset, so it must handle events that arrive late or out of order.
The Dataflow paper from Google (Akidau and colleagues, VLDB 2015) makes a point worth keeping in mind here. Its authors prefer the words "unbounded" and "bounded" for describing data, and keep "streaming" and "batch" for the engines that process it, because "unbounded datasets have been processed using repeated runs of batch systems since their conception, and well-designed streaming systems are perfectly capable of processing bounded data." In other words, a micro-batch job every five minutes is a legitimate answer to a five-minute freshness budget. You do not need a streaming engine to be fresh enough.
The third option is the one AI teams forget, and for LLM applications it is often the right one: do not move the data at all. When an assistant needs to know where order 48213 is right now, it can call the order system's API at the moment the question is asked. The answer is as fresh as the source, and there is no copy to go stale. It only works for single-record lookups, not aggregates, and it loads the source system, so it needs limits. But for "what is the status of X" questions, common in support and operations, it beats both batch and streaming.
An illustration: one grocery app, three answers
Take an invented example. An online grocery business in Hyderabad wants three AI features this quarter.
The first is a seven-day demand forecast per store and SKU, read by buyers each morning. Its inputs are sales history, promotions, holidays and weather. None of those change meaningfully within an hour, and the buyers look at the forecast once a day. This is a batch job.
The second is a fraud check on payments at checkout. Some of its inputs are slow (account age, past chargebacks), and some are fast: how many payment attempts this account and this device made in the last five minutes, and whether the delivery address changed in the last hour. A burst of attempts is exactly the signal, and a nightly job cannot see it. This feature needs streaming for those two or three fast inputs, and only those. The slow ones can come from the same nightly batch as everything else.
The third is a support assistant that answers "where is my order" and "why was I charged twice". The tempting design is to stream order events into the assistant's search index. The better design is to give the assistant two tools, one that reads an order's status and one that reads a customer's recent payments, and to let it call them when the customer asks. The index keeps only slow-changing content such as refund policies. Our article on tool calling covers how to make those calls safe.
Three features, three answers. Picking one architecture for the whole platform first would have got at least two of them wrong.
What streaming costs
The engineering cost of streaming comes from time. Apache Flink's documentation distinguishes processing time, "the system time of the machine that is executing the respective operation", from event time, "the time that each individual event occurred on its producing device." In a batch job yesterday's data is all present before you start; in a stream the two clocks diverge constantly. A rider's phone loses signal in a basement and uploads twenty minutes of location events at once. Events arrive late and out of order as a matter of routine.
Stream processors handle this with watermarks, which Flink describes as markers that "flow as part of the data stream and carry a timestamp", signalling that event time has reached that point. Anything arriving after the watermark has passed it is a late element, and you have to decide what to do with it: drop it, update a result you already emitted, or send it somewhere for correction. The Dataflow paper is honest that "for most real-world distributed data sets, the system lacks sufficient knowledge to establish a 100% correct watermark." That is the deal you accept with streaming: lower latency in exchange for answers that may be revised.
The second cost is duplication. The classic way to get both fresh and correct numbers was the Lambda architecture: a batch layer that recomputes everything accurately, plus a speed layer that covers the gap since the last batch. Jay Kreps described the problem with it in 2014 as "maintaining code that needs to produce the same result in two complex distributed systems", and added: "I don't think this problem is fixable." His alternative was to keep the full event log in a system like Kafka and, when logic changes, run a new streaming job from the start of the log into a new table, then switch over. Either way, every feature computed in two places can disagree with itself.
Where models go wrong: the batch and online versions of a feature
That disagreement has a name in machine learning: training-serving skew. Google's guide defines it as "a difference between performance during training and performance during serving", and lists among its causes "a discrepancy between how you handle data in the training and serving pipelines." Splitting a feature across batch and streaming is an easy way to create that discrepancy. Training reads "payment attempts in the last five minutes" from a warehouse query someone wrote in SQL. Serving reads it from a stream job someone else wrote in Java, which counts retries differently and uses processing time instead of event time. The model was trained on one feature and served another.
Rule #32 says why this keeps happening: "At serving time, you are doing online processing, whereas training is a batch processing task." Its advice is to reuse code between the two wherever possible and to avoid using two different programming languages, because that makes sharing code "nearly impossible". Rule #29 gives the strongest fix: log the features you actually used at serving time and train on those logs. The guide reports that the YouTube home page switched to logging features at serving time "with significant quality improvements and a reduction in code complexity".
Feature stores attack the same problem from the storage side. Feast, an open source feature store, keeps an online store for low-latency serving in which "only the latest feature values are stored", and builds training data from history with point-in-time joins, which look backwards from each training example's timestamp so the model only sees values that existed at that moment. One detail is worth knowing even if you never use Feast: by default the join only checks the event timestamp, so a value that was backfilled or corrected later can still leak into training data. It offers a filter_by_created_timestamp option to restrict results to values that would have been available online at the time. If your batch pipeline routinely corrects yesterday's data, your training set may contain knowledge your live model never has.
Real-time for LLM and RAG applications
For generative AI, the freshness question splits differently. The model itself is fixed; what goes stale is the context you give it. In a RAG system that means the search index. A policy document updated on Monday and re-indexed on Sunday gives a week of confidently outdated answers, and a document deleted from the source but not from the index is worse, because it may be one nobody should see any more.
Most document collections change slowly enough that an hourly or nightly re-index of changed files, with deletes handled explicitly, is the right design. What does not belong in the index at all is anything that changes by the minute: balances, stock, ticket status, sensor readings. Those should come from a tool call at answer time, as in the grocery example. Our RAG explained article goes through the other ways retrieval goes wrong.
The access question gets harder once you have three paths. A warehouse, a feature store and a live API each tend to grow their own permissions, so a user barred from a store's margin in the dashboard might still get it through the assistant. This is the problem CloudOEngine's data layer is built around: databases, files and camera streams are connected on one platform, under one permission model and one audit trail, whichever path the AI uses to read them.
Live video: a fast number and a correct one
Live video is the extreme case of real-time data, and it shows the trade-off between a fast number and a correct one most clearly. A people count from a camera is useful in the moment, but the number that goes into a report needs checking. CloudOEngine's Vision AI counts with two independent trackers, sends the crossings where they disagree to a human review queue, and ships a finalised count with a published accuracy report.
Side by side
| Batch | Streaming | Query-time lookup | |
|---|---|---|---|
| Typical age of data | Minutes to a day | Seconds | Live |
| Good for | Training, forecasts, reports, aggregates | Short-window counts, anomaly and fraud signals | Status of one order, account or asset |
| Main difficulty | Staleness that nobody notices | Late events, two code paths, skew | Load on the source system, permissions per call |
| How to fix a mistake | Rerun the job | Replay from the log, revise results | Fix the source; nothing cached to clear |
How to decide, in order
- List every input the AI feature uses and write the oldest value you would accept for each. Be honest; "real-time" in a requirements document often means "today".
- Serve everything with a budget of an hour or more from batch, even if you run that batch every fifteen minutes.
- For single-record facts that change by the minute, give the model a tool that reads the source system when asked, with rate limits and the caller's permissions.
- Stream only what remains: aggregates over short windows that must be seconds old. Write each one once, and log the values you serve so you can train on them.
- Add a freshness check on every input with an alert at its budget, so staleness becomes an incident instead of a slow decline.
Steps 2 and 3 often cover the whole feature.
Acting on fresh data raises one more question: who approves the action. A real-time signal that should trigger something, such as holding a suspicious order or reordering stock, is a good fit for CloudOEngine's Autopilot, where a triggered agent proposes the action and a person approves it in the app or through an email approve link before it runs.
How CloudOEngine helps
CloudOEngine is one platform and one console for connecting data, including databases, files and camera streams, building pipelines, and running AI: an LLM gateway, agents with tool access, RAG, Vision AI and live video. Batch tables, document collections and live lookups sit under one permission model and one audit trail, so the path an AI feature uses to read data does not change who is allowed to see it.
Governance is included, not upsold: tenant isolation, role-based access, audit logs and per-tenant encrypted secrets.
Agents in CloudOEngine run real tools, for example filing a ticket, and every step and tool call is traced and inspectable. That covers the query-time path from this article: you can see which record the agent read. With Autopilot, agents can be triggered and governed by approval rules, so a person approves an action before it runs.
CloudOEngine's AI reads your real data schemas to propose KPIs, which is a practical place to start the freshness spreadsheet: the KPIs you adopt tell you which tables need which budget.
For video, Vision AI counts with two independent trackers, sends disagreements to a human review queue for your staff to check, and ships each finalised count with a published accuracy report that shows every counted crossing. CloudOEngine has 500+ connectors and is built in Bengaluru, India.
Book a demo or see the Data layer.
Frequently asked questions
What is the difference between real-time and batch data for AI?
Batch data is processed in scheduled runs over a finished set of records, so it is complete but hours or a day old. Real-time data is processed as events arrive, so it is fresh within seconds but has to cope with late and out-of-order events. Most AI applications need a mix of both.
Does my AI application need real-time data?
Only if the decision loses value faster than your batch cycle. A payment fraud check or a live stock answer does; a demand forecast, a churn score or a monthly report usually does not. Write down how stale each input can be before the answer becomes wrong, and stream only the inputs with a budget measured in minutes.
What is training-serving skew?
Google's Rules of Machine Learning define it as a difference between performance during training and performance during serving. A common cause is computing the same feature one way in a batch job for training and another way in a streaming job for serving.
What is a point-in-time join?
It builds training data by joining each example only with feature values that existed at that example's timestamp, so the model never learns from information that was not available yet. Feature stores such as Feast do this by looking backwards from each row's timestamp.
How do I keep a RAG system's answers up to date?
Re-index changed documents on a regular cycle and remove deleted ones, and do not put fast-changing facts such as order status or stock levels into the index at all. Let the assistant fetch those through a tool call to the source system when the question is asked.
Is the Lambda architecture still a good idea?
It works, but it means writing the same logic twice, once for batch and once for streaming, and keeping both in agreement. Jay Kreps argued in 2014 that this problem is not fixable and proposed reprocessing from a retained log instead, which became known as the Kappa architecture.
Sources
- Rules of Machine Learning: Best Practices for ML Engineering (Martin Zinkevich, Google for Developers)
- The Dataflow Model: A Practical Approach to Balancing Correctness, Latency, and Cost in Massive-Scale, Unbounded, Out-of-Order Data Processing (Akidau et al., VLDB 2015)
- Questioning the Lambda Architecture (Jay Kreps, O'Reilly Radar, July 2014)
- Timely Stream Processing (Apache Flink documentation)
- Point-in-time joins (Feast documentation)
- Online store (Feast documentation)
