Realtime Computing for AI: Real-Time Data Streaming, Latency and Cost

Realtime computing for AI on live streams: deadlines versus batch, how events reach the model, where latency goes and what drives GPU cost per request.

Realtime Computing for AI: Real-Time Data Streaming, Latency and Cost
Written by TechnoLynx Published on 19 May 2025

In realtime computing, “real-time” describes a deadline, not a speed. A system is real-time when an operation only counts as correct if it finishes within a specified time of the event that triggered it. For AI scoring a live data stream, each event (a payment, a sensor reading, a click) is processed incrementally as it arrives. Batch processing works differently: batch systems handle billions of records with flexible analysis, but their high latency makes them unreliable for stream data. When a streaming AI system misses its latency target or costs too much to run, the fix can lie in the serving path (queueing, batching, state handling, GPU provisioning) without replacing the model.

What Is Real-Time Data Streaming with AI?

Real-time data streaming with AI joins two things: an event stream that carries data continuously from where it is produced, and a model that scores those events in real time. The Apache Kafka documentation defines event streaming as capturing data in real time from sources such as databases, sensors, mobile devices and applications, storing those streams durably, processing and reacting to them in real time or retrospectively, and routing them to other systems. The Apache Flink documentation describes the same data as an unbounded stream: one with a start and no defined end, which has to be processed continuously, with events handled promptly after ingestion.

The model itself need not learn from the stream. A 2021 paper on real-time intelligent big data processing describes a deployment pattern in which models are trained offline on batch data and then used for real-time inference in production. Chip Huyen’s 2022 overview of real-time machine learning calls the broader goal using real-time data to make more accurate predictions and to adapt models to changing environments. Online retraining exists, but both online inference and continual learning require mature streaming infrastructure.

Realtime Computing Deadlines, Near Real-Time and Throughput

The deadline definition has a practical consequence that people often miss. A real-time process fails if it does not complete within its deadline, whatever the system load at the time. A tournament chess program that runs out of its allotted time loses the game, so missing the deadline is the failure itself.

Real-time is also not the same as fast. Real-time computing is often confused with high-performance computing, but a supercomputer running a simulation is not doing real-time computation, and a heavily loaded web server that slows down without timing out is not a real-time system either. In the words of the same reference, high performance is how much processing gets done in a given time, while real-time is the ability to produce a useful output in the time available; consistent output matters more than high throughput. A GPU cluster that serves a huge volume of tokens per second can still miss every deadline that matters if its tail latency is unbounded.

“Near real-time” names the delay that automated processing or network transmission adds between an event happening and the processed data being used. A near-real-time display shows the world as it was at the current time minus the processing time.

Mode What it promises Typical AI example What breaks it
Real-time Output within a stated deadline per event, regardless of load Inline fraud scoring before a payment is approved Unbounded tail latency, queue build-up under bursts
Near real-time Output delayed by processing and transmission time; features can be seconds stale Recommendations from features recomputed by a stream engine Staleness growing past what the use case tolerates
Batch Results on a schedule; high latency, very large volumes Nightly scoring of every customer record Scoring data that changes faster than the schedule

Real-Time Processing vs Batch Processing: When to Stream

Stream an AI workload when the value of a prediction decays faster than your batch schedule. The authors of the 2021 real-time big data paper argue that real-time data is the most valuable for capturing shifts in consumer preferences or in fraudsters’ behaviour. If the decision can wait until tomorrow morning, batch is the simpler option.

The cost comparison is less one-sided than it looks. Huyen points out that the common belief that online prediction is less efficient than batch does not necessarily hold: with online prediction you do not generate predictions for users who never show up, whereas a daily batch job that scores every user spends compute on those who never visit. She makes a similar point about computation: stateful streaming can be cheaper than stateless batch, because a 30-day sliding window recomputed in every batch repeats work that a stateful stream job does once. The Dataflow model paper (VLDB 2015) frames the underlying constraint: on unbounded data you can never fully optimise correctness, latency and cost at once, so the system has to let you choose the trade-off for each use case.

Inside Spark, the choice is largely a trigger setting, within the sources, operators and sinks that Real-time Mode supports. Spark’s 3.5 Structured Streaming guide states that the default micro-batch engine reaches latencies of about 100 ms at best with exactly-once guarantees, while the experimental continuous processing mode (introduced in Spark 2.3) reaches about 1 ms end to end with at-least-once guarantees. The Spark project describes its Real-time Mode as bringing stateless tasks down to single-digit milliseconds, with micro-batch and real-time execution sharing a codebase so that moving between cost-effective ETL and sub-second streaming takes only small query changes. Managed platforms draw the same line at the serving layer: Amazon SageMaker AI positions real-time inference as a persistent endpoint for sustained low-latency traffic, with limits of 25 MB payloads and 60-second processing for regular responses.

Three questions settle the choice: what the per-event deadline is, whether the features need state over long windows, and what delivery guarantee the downstream action requires (exactly-once billing versus at-least-once alerting).

How Live Events Reach the Model

A streaming AI pipeline moves events through a transport layer and a computation layer before the model scores them. Huyen describes streaming infrastructure as a transport such as Kafka or Kinesis that moves events, plus a computation engine such as Flink SQL, KSQL or Spark Streaming that processes them and keeps state, for example dividing user activity into sessions. In the 2021 Stream Cube system, the computation engine serves two jobs: answering user queries and computing the input metrics that AI models consume. That production risk engine, running on four servers, responds in under 50 milliseconds while processing over 50,000 transactions per second.

Computing features efficiently is a hard design problem in its own right. Real-time features are computed when the prediction request arrives, so they are fresh to the millisecond, but their computation latency adds directly to user-facing latency and becomes harder to sustain as traffic grows. Near-real-time features are precomputed asynchronously by a stream engine and looked up at prediction time, so they add no feature latency to the request, at the price of staleness measured in seconds.

Time has to be handled explicitly as well. Event time is when an event occurred on the device that produced it, and processing time is the clock of the machine running the operator; processing time gives the lowest latency, while event-time processing waits for out-of-order events. Watermarks carry event-time progress through the stream: a watermark with timestamp t declares that no more events at or before t should arrive. The Dataflow paper notes that watermarks are sometimes too fast (late data arrives behind them) and sometimes too slow, because one slow record can hold back the whole pipeline. For a model scoring windowed features, that choice decides both how quickly a score is emitted and whether it was computed on complete data.

Which Technologies Make up a Real-Time AI Streaming Stack?

The usual layers and example tools:

Layer Job Examples
Event transport Durable streams of events between systems Apache Kafka (with Kafka Connect), AWS Kinesis
Stream processing Transformations, joins, windows, event-time handling, state Apache Flink, Spark Structured Streaming, Kafka Streams
State store Keyed state across events, checkpointed for recovery RocksDB state store in Spark, Flink local state
Feature layer Real-time or precomputed near-real-time features for scoring Stream-computed features looked up at request time
Model serving Batching, concurrent model instances NVIDIA Triton Inference Server, vLLM for LLMs
Measurement Latency breakdown, utilisation, backpressure Triton perf_analyzer, Flink Web UI backpressure view

Generative models stretch the serving layer further, because they generate output one token per iteration rather than as one score; streaming LLM output and other generative workloads are covered in their own article.

What Use Cases Need Real-Time AI Streaming Today?

Kafka’s documentation lists processing payments and financial transactions in real time, tracking fleets and shipments, continuously analysing sensor data from factories and wind parks, and reacting immediately to customer interactions and orders. The Spark project names inline fraud detection, live personalisation and real-time alerting as the targets of its low-latency mode.

Deadlines differ widely between these cases. The 2021 Stream Cube paper describes identifying ticket scalpers within 0.1 seconds, while modelling each buyer’s past behaviour, as far harder than fraud detection in internet finance. The Dataflow paper’s motivating example is ad billing, where advertisers want viewing statistics as close to real time as possible and correctness is paramount because money is involved. Live media sits at the strict end: tolerable latency for live audio processing is estimated at between 6 and 20 milliseconds. Video and network workloads have their own budgets, discussed in real-time computer vision for live streaming and in what the latency budget actually allows in telecom.

Where Does the Latency Go When a Model Scores a Live Stream?

In a streaming AI system, latency can pile up around the model as well as inside it. The authors of Clockwork (OSDI 2020) observe that DNN inference has deterministic performance with negligible variability, because inference involves no conditional branches. When a DNN scoring model shows wide tail latency, we would therefore look first at queues, state and the pipeline.

We would check the serving queue first. NVIDIA’s Triton perf_analyzer splits server latency into queue time (waiting for a model instance) and compute time, which includes copying data to and from the GPU. In the tool’s own example at a request concurrency of 4, average server latency is about 45.6 ms, of which about 33.6 ms is queue and about 11.8 ms is inference compute. In that example roughly three-quarters of the latency is spent waiting, not computing (33.6 / 45.6 ≈ 0.74).

Upstream, the stream engine adds its own delays. Large keyed state held in JVM memory can cause garbage-collection pauses that make Spark micro-batch times vary widely, which is why Spark 3.2 added a RocksDB state store that keeps state in native memory and local disk. Moving a state store to another executor costs the time needed to load checkpointed state, and blocking offset management delays processing until it completes, which is what Spark’s changelog checkpointing and asynchronous progress tracking address. Flink keeps task state local and checkpoints it asynchronously and incrementally, to limit the impact on processing latency. Event-time windows add the wait for watermarks on top of all this.

Finding the Bottleneck, in Order

  1. Write down the deadline per event.
  2. Check the stream engine for backpressure: in Flink, a slow operator fills its input buffers, the pressure spreads upstream to the sources, and the Web UI job graph shows which tasks are busy, idle or backpressured.
  3. Remember that the bottleneck can move: firing windows can shift it between tasks, and data skew can leave some subtasks idle while others are saturated.
  4. Look at state: large state and executor relocation show up as micro-batch time variance and latency.
  5. Split serving latency into queue and compute with a load generator; perf_analyzer defaults to a concurrency of 1, the lowest possible load, so raise concurrency to see how the queue behaves.
  6. Only after that, profile the model’s compute.

How Streaming Inference Changes GPU Utilisation and Cost per Request

Streaming inference ties GPU cost to the offered request rate. A streaming endpoint has to serve whatever arrives within its latency target. A 2026 study of LLM infrastructure cost makes the point precisely: GPU utilisation is not a parameter to assume but a result of offered request rate, latency SLO, model and deployment configuration. At low load the GPU sits underused, waiting on memory transfers; as load rises, utilisation improves but queueing raises latency, and the SLO caps how much load the deployment can take.

The measured effect is large. Across 42 vLLM benchmark runs on H100 GPUs, effective cost per token varied 17.5 to 36.3 times within a single configuration on identical hardware, with only the offered request rate changing, and spanned $0.21 to $15.25 per million output tokens across configurations. On A100s the same cliff shape appeared with a narrower 7.0 to 11.4 times spread. The authors also treat the latency SLA as a price: tightening it forces a lower sustainable load and so a higher cost per token. Their recommended remedies are provisioning changes: consolidate tenants, scale replicas to the offered load, coalesce requests, or fall back to a serverless endpoint below the crossover point.

Batching is a major lever on the serving path. Triton’s dynamic batching combines individual inference requests into a batch on the fly; in a worked example, the latency reduction came mainly from less time waiting in the queue. For autoregressive models, continuous batching goes further by scheduling per iteration, so a finished sequence frees its slot for a newly arrived request instead of the request waiting for the whole batch to finish. The Orca paper (OSDI 2022) reports 36.9 times the throughput of NVIDIA FasterTransformer at the same latency on GPT-3 175B, and Anyscale reports up to 23 times throughput with continuous batching and memory optimisations in vLLM. Both gains come from scheduling and memory management in the serving system. The limits still apply: continuous batching is bound by GPU memory, and once the server is saturated there are fewer chances to inject new requests immediately. MLPerf’s server scenario sends queries in a Poisson pattern to mimic a server’s query arrivals.

TechnoLynx’s practice follows from this: when a deployed AI feature hits cost or latency pressure, TechnoLynx profiles and tunes the serving path (batching, provisioning, caching, runtime configuration) before recommending a different model.

What Are the Hardest Problems in Real-Time AI Streaming?

In Chip Huyen’s assessment, real-time machine learning is largely an infrastructure problem: online inference needs mature streaming infrastructure that data science and platform teams have to build together. Online features alone can number in the hundreds or thousands per prediction, with joins and aggregations over large windows, and computing them efficiently and affordably is very hard.

After that come three recurring tensions. Correctness against latency: no system fully optimises both at once, and watermarks can be wrong in either direction. Utilisation against deadlines: the latency SLO caps achievable utilisation, and utilisation-naive estimates understate self-hosting cost most for low-traffic workloads. And moving bottlenecks: an operator that keeps up under steady load can become the constraint when windows fire or keys skew. Each has to be re-checked whenever traffic shape, feature definitions or deadlines change, so latency and cost on a live stream belong in monitoring, not a one-off test.

FAQ

What Are the Two Types of Streaming?

In Apache Flink’s terms, streams are either unbounded (a start but no defined end, processed continuously) or bounded (a fixed-size data set that can be processed as a whole). In execution terms, Spark distinguishes micro-batch processing, around 100 ms at best, from continuous processing at around 1 ms.