Real-Time Data Pipelines for AI: Architecture That Works

Real-Time Data Pipelines for AI: Architecture That Works

What happens when a fraud model scores a transaction using data that is already six hours old? Or when a support assistant answers a customer with a policy that changed last week? The model isn’t wrong, exactly. The pipeline is. For most AI systems in production, freshness of data matters as much as the quality of the model itself, and that is why real-time data pipelines have moved from a niche engineering concern to a core piece of AI infrastructure. (Data pipeline)

This article walks through how these pipelines are built, where teams commonly get them wrong, and which design choices tend to survive contact with production traffic.

What a real-time data pipeline actually does

A real-time data pipeline moves events from where they happen to where a model can use them, with latency low enough that the prediction still reflects the current state of the world. That usually means seconds, sometimes milliseconds. It is not the same thing as “fast batch.” A nightly job that finishes in ten minutes is still a batch job.

A working pipeline typically handles five jobs at once:

  • Ingest events from applications, sensors, databases, or clickstreams.

  • Transform them: clean, enrich, join, and aggregate.

  • Compute features that a model will consume at inference time.

  • Serve those features to a model server or write them to a low-latency store.

  • Log inputs, outputs, and decisions for monitoring, debugging, and audit.

Each stage has its own failure modes, and the interesting engineering happens at the seams between them.

Why AI workloads stress pipelines differently than analytics

Why AI workloads stress pipelines differently than analytics

Classic streaming analytics answers questions for dashboards. AI pipelines answer questions for models, and models are far less forgiving.

A dashboard that shows a metric 30 seconds late is fine. A recommendation model that sees a feature vector assembled from mismatched timestamps is not. This is the heart of training-serving skew: the features a model learned from during training were computed one way, and the features it receives in production are computed another. The model’s accuracy quietly collapses, and nobody notices until the business metric moves.

The second difference is replay. ML teams need to reconstruct historical feature values to retrain models and backfill new features. A pipeline that only moves data forward, with no ability to rewind, forces teams to maintain a parallel batch system just for training. That duplication is where most of the operational pain comes from.

The log as the backbone

Most serious real-time architectures are built on an append-only, partitioned, replicated log. Apache Kafka is the best-known example, open-sourced by LinkedIn in 2011 and a top-level Apache project since October 2012. The key property is not speed. It is that consumers track their own position in the log and can replay history on demand.

That single design choice solves several AI problems at once. A new feature can be computed by replaying the last ninety days of events through the same code that will run in production, which eliminates a whole class of skew. A model retrain can pull a consistent snapshot. A bug in a downstream consumer can be fixed and the data reprocessed without touching the source.

The trade-off is operational: logs need retention policies, partition strategies, and schema governance. Teams that treat the log as an infinite free resource discover the cost of retention the hard way.

Lambda, Kappa, and what people actually run

Two architectural patterns dominate the conversation.

The Lambda architecture, popularized by Nathan Marz in the early 2010s, runs a batch layer and a speed layer in parallel, then merges the results at query time. It is dependable and well understood, but it means maintaining two codebases that must produce identical outputs. In practice, they drift.

The Kappa architecture, proposed by Jay Kreps in a 2014 essay questioning the Lambda approach, argues that a single stream-processing path is enough if the log is replayable. Reprocessing replaces the batch layer.

Dimension Lambda Kappa
Code paths Two (batch + stream) One (stream only)
Reprocessing Rerun batch job Replay the log
Operational burden Higher Lower, if replay is fast
Historical depth Naturally deep Limited by log retention
Skew risk Higher, two implementations Lower, one implementation

Neither wins outright. Lambda still makes sense when historical reprocessing is genuinely expensive or when the batch layer predates the streaming one. Kappa wins when the log retention window covers the retraining horizon, which for many teams is 30 to 90 days.

Event time, watermarks, and late data

Here is a mistake that shows up in almost every first-generation pipeline: using the moment a system processed an event instead of the moment the event actually happened. Mobile clients buffer events. Network partitions delay them. A payment authorization may arrive at the pipeline minutes after the transaction occurred.

Event-time processing uses the timestamp embedded in the event. Watermarks are the mechanism that tells the processing engine how far it can safely advance, balancing completeness against latency. Apache Flink and Apache Beam both formalized these concepts, and the Beam programming model in particular is worth reading if you want the mental model rather than a specific vendor’s implementation.

The practical guidance: decide explicitly what happens to late events. Drop them, route them to a side output, or allow windows to fire again with updated results. What you must not do is leave it undefined, because undefined behavior in late-data handling is one of the most common sources of silent feature corruption.

Exactly-once is a property of the whole pipeline

Streaming engines advertise exactly-once semantics, usually implemented with checkpointing plus idempotent or transactional sinks. Kafka added transactional and idempotent producer support in version 0.11 in June 2017, which made end-to-end guarantees far more achievable.

But exactly-once is only as strong as the weakest sink. If the pipeline writes to a vector database that upserts without a deterministic key, or a feature store that overwrites on a timer, duplicates creep back in. The honest framing is: exactly-once processing plus idempotent writes equals effective exactly-once. Teams that skip the idempotency work on the sink side often find duplicate rows in their training data months later.

Feature stores and the offline-online gap

Feature stores emerged around 2019 and 2020 to solve a specific problem: computing the same feature definition for both training (offline, high throughput) and inference (online, low latency). The point is not storage. The point is that one definition produces both values, which structurally prevents training-serving skew.

What actually works in practice is narrower than the marketing suggests. A feature store pays off when you have many models sharing features, or when online latency requirements are strict. For a single model with a handful of features, a well-instrumented streaming job writing to a key-value store is usually simpler and easier to debug.

The common mistake is adopting a feature store before the team has clean event schemas. A feature store built on inconsistent upstream data just distributes the inconsistency faster.

Streaming ingestion for retrieval-augmented generation

Since roughly 2023, a new pattern has taken hold: keeping a vector index fresh through streaming ingestion. Documents are chunked, embedded, and upserted into a vector index as they change, so a retrieval-augmented generation system answers with current information rather than a snapshot from the last full reindex.

This pattern has real costs. Embedding is compute-heavy, so naive per-document re-embedding on every edit gets expensive fast. Deduplication matters more than people expect, because near-identical chunks crowd out diverse results. And deletion is genuinely hard: removing a document from a vector index reliably requires tracking chunk lineage, rather than deleting solely by document ID.

A workable approach is to treat the vector index as a derived view of the log, with idempotent upserts keyed on a stable chunk hash and a tombstone event for deletions. That keeps the index rebuildable, which is the property you will want the first time an embedding model changes.

Choosing between batch and real-time

Not every AI workload needs a streaming pipeline, and pretending otherwise burns engineering budget. A useful test is to ask how much the prediction degrades when the feature is stale by an hour. If the answer is “barely,” batch is fine.

Where the decision is genuinely close, it helps to think in terms of cost and operational surface rather than ideology. A structured comparison of latency requirements, replay needs, and maintenance burden is laid out in this guide to choosing between batch and real-time inference, which is a sensible starting point before committing to a streaming stack.

Multi-tenant pipelines and data isolation

AI platforms increasingly serve many customers from shared infrastructure, and that raises a question the streaming layer cannot dodge: where do tenant boundaries live? Options include separate topics per tenant, a tenant key in the partition scheme, or separate clusters entirely. Each has different blast-radius characteristics when something goes wrong.

The isolation decision also affects feature computation, because a join that accidentally crosses tenant boundaries produces a data leak rather than an error. Approaches for handling this safely are covered in this walkthrough on separating tenant data in an enterprise assistant, which is worth reading before designing partition keys.

Cost control is a pipeline feature

Streaming pipelines generate cost in places that surprise teams: cross-availability-zone replication, long retention windows, and egress between regions. A pipeline that looks cheap in staging can produce a startling bill once real event volume arrives.

Two habits help. First, measure transfer costs explicitly rather than lumping them into a general infrastructure line, since the breakdown is what makes optimization decisions obvious. A method for tracking cloud data transfer costs in more detail than most billing dashboards provide is a good complement to pipeline monitoring.

Second, tier your retention. Keep hot data for days, warm data for weeks, and archive the rest. Most retraining jobs do not need millisecond access to ninety-day-old events.

Testing a pipeline before it fails

The failure that hurts most is not a crash. It is a pipeline that keeps running and produces subtly wrong features. Recovery drills catch this class of problem, and they are far cheaper than the incident they prevent.

A drill should include: replaying a known window of events and confirming outputs match a recorded baseline, simulating a sink outage mid-checkpoint, and verifying that a schema change upstream produces a clear error rather than silent nulls. The same discipline applied to stateful stores is described in this guide to building a recovery drill for a managed database, and the logic transfers directly to streaming state.

Observability that catches skew early

Standard infrastructure metrics will not tell you that a feature distribution has shifted. You need statistical monitoring on the feature values themselves: mean, variance, null rate, and cardinality, compared against a training baseline.

Set alerts on distribution drift as well as pipeline lag. A pipeline with zero lag can still be feeding a model garbage if an upstream join started returning empty results.

Conclusion

Real-time data pipelines for AI are less about latency numbers and more about consistency. The architectures that hold up share a few traits: a replayable log as the source of truth, one code path for training and serving features, explicit handling of late and out-of-order events, idempotent writes at every sink, and monitoring that watches feature distributions rather than just throughput. Get those right and the pipeline becomes boring, which is exactly what you want from infrastructure that a model depends on.

FAQ

Do AI models always need real-time data?

No. Many models perform well with hourly or daily refreshes. Real-time matters when the underlying signal changes faster than the refresh interval and the prediction degrades meaningfully as a result, as with fraud detection, dynamic pricing, or conversational assistants answering from live documents.

What is the difference between Lambda and Kappa architecture?

Lambda runs separate batch and streaming paths and merges their outputs, which is reliable but requires maintaining two implementations. Kappa uses a single streaming path and handles reprocessing by replaying the log, which reduces duplication but depends on retaining enough history.

Why is training-serving skew so common?

Because feature logic is usually written twice: once in a batch framework for training and once in a streaming job for serving. Small differences in time windows, joins, or null handling compound into large accuracy gaps. Computing features from a single definition is the most reliable fix.

How is exactly-once delivery achieved in practice?

Typically through checkpointing combined with idempotent or transactional sinks. The processing engine guarantees each event is handled once within its own state, but the end-to-end guarantee only holds if the destination can safely absorb retries without creating duplicates.

What should happen to late-arriving events?

That decision should be explicit. Teams can drop late events, route them to a side output for separate handling, or allow windows to re-fire with corrected results. Leaving the behavior undefined is the real risk, because it produces inconsistent features without any visible error.

How much history should a pipeline retain?

Enough to cover the retraining horizon, which is often 30 to 90 days, plus a margin for incident investigation. Retention beyond that is usually cheaper in cold storage than in the hot streaming tier, and tiering retention is one of the simplest cost levers available.

Latest articles

Scroll to Top