Lambda and Kappa architectures
Two ways to get quick and correct results from an event stream: Lambda runs a batch path and a speed path with the logic written twice; Kappa keeps one streaming job and repairs results by replaying the retained log.
What it is
Both architectures answer one problem: deriving results from a stream of events when you want them sooner than a scheduled batch run would deliver them (seconds to hours, depending on the pipeline) and you also want them to end up right. Both start from the same foundation, a record of the raw events that grows by appending, is kept unchanged and is treated as the system of record, so a derived result can be rebuilt from it for as long as the events it depends on are still retained. The difference is how many processing paths read that record and how a wrong result gets repaired.
Lambda has three layers. The batch layer reads the whole master data set and precomputes views; because it sees all the data, it can correct an earlier mistake by recomputing and replacing the stored view, and its output usually lands in a store that is replaced by each new run rather than edited in place. The speed layer processes events as they arrive and covers the gap left by the batch layer's lag; its views may be less complete, and they are swapped out when the batch view for the same period becomes available. The serving layer answers queries from both. The same transformation is written twice, once for each processing system, and the results are stitched together at query time. Nathan Marz described the pattern first, in a 2011 post that called it the batch/realtime architecture.
Kappa drops the batch layer. Jay Kreps proposed it in 2014 after running Lambda-style pipelines at LinkedIn: keep one stream processing job, and store the input in a log that keeps the data as long as you might want to reprocess it (a 30-day horizon means 30 days of retention). When the code changes, start a second instance of the job from the beginning of the retained data and point its output at a new table. Once it has caught up with the live job, switch the application to the new table, then stop the old job and delete its table. Reprocessing happens when the logic changes and the results need recomputing, not on a schedule. Keeping both tables for a short while gives you an instant revert: point the application back at the old one.
The log that makes this work is the kind a consumer can re-read. In Apache Kafka 4.2, a consumer's position in a partition is a single offset, and the design documentation describes rewinding to an older offset to consume the data again, giving the case of a consumer bug found after messages were processed as the reason you'd want to. A second reader of the same partitions is just another position in the same log, which is what lets the reprocessing job run beside the live one.
Why a stream result is provisional at all: events arrive out of order, and stream processors cope by grouping them into event-time windows and using a watermark to decide when a window is done. Events that turn up after the watermark can be dropped, which is one reason a batch or backfill pass over the same period gives a different, usually more complete, answer. Stream processing and windows covers the mechanics.
When to use it
Reach for Lambda when the batch side already exists and does real work of its own: a warehouse that runs on a schedule and is trusted as the accurate record, with a thin live layer added for freshness. Lambda's original target was complex asynchronous transformations that need latency from a few seconds to a few hours, with a news recommendation pipeline as the example. In production the split often looks like a streaming pipeline that runs live and a batch pipeline scheduled at a delay to reprocess for the most accurate result.
Reach for Kappa when the live result and the corrected result should come from the same logic, the input is retained at least as far back as any repair you expect to make, and recomputation is rare. Scale the reprocessing job wider than the live one so it catches up quickly. When the retained log is too short or too busy to replay from, the input can come from somewhere else: Uber's backfiller reads a Hive table as if it were a stream, pulls it in increments, computes windows in the order they occurred, and widens the watermark so each trigger covers about two hours of events, which let it backfill several days of data in about a day.
When not to
Don't run both paths when one will do. Kreps's own advice is to use a batch framework when latency doesn't matter, a stream framework when it does, and to combine them when you have no other choice. If results may be hours old without harm, a scheduled batch job that rewrites its output is simpler than either architecture, and if the stream result is disposable (a live dashboard nobody reconciles against), a single stream job with no replay plan is enough.
Kappa also has limits that the slogan hides. Replay reaches back as far as retention and no further. Pushing weeks of archived events back into the live message system to replay them can overwhelm it, and a replayer has to reproduce the original order closely enough that event-time windows and watermarks behave as they did the first time; Uber rejected a Hive-to-Kafka replayer for both reasons. And a reprocessing job that writes straight into the live output table loses the clean swap and the easy revert that make the pattern safe.
Compared
| Approach | Code paths | How a wrong result is repaired | When it's the right pick |
|---|---|---|---|
Batch alone | One | Rerun the job; the new output replaces the old | Results may be hours old without harm |
Stream alone, no replay | One | Patch by hand, or accept the error | Results are disposable and nobody reconciles them |
Lambda | Two, kept in step | The scheduled batch view replaces the speed view for that period | A trusted batch warehouse already exists and needs a thin live layer |
Kappa | One | A second job replays the retained log into a new table; readers switch | Live and corrected results must share one logic; the log is retained; recomputes are rare |
In a picture
Step 1 of 3
Live
One streaming job reads the retained log and writes its results to table A, which the application reads.