Your analytics need two things that pull in opposite directions: numbers that are seconds old, and numbers that are still right after a bug fix, a late event or a changed business rule. Around 2011 no single tool gave both: Hadoop recomputed everything but hours late, and Storm was fast but could not recompute history.
The Lambda architecture answered with two pipelines, the Kappa architecture with one pipeline and a log you can replay. This post compares both with a diagram: how they reprocess, retain data and stay correct, and what teams build instead today.
Where the two architectures came from
Nathan Marz, the creator of Storm, described the first one in How to beat the CAP theorem in October 2011. His starting point is that any query is a function of all the data, and that data should be stored as immutable, time-stamped facts: an update is a new fact, never an overwrite. A system built that way can always recompute its answers, so a bug that wrote bad results is fixed by fixing the code and recomputing.
Jay Kreps, one of Kafka's creators, replied in Questioning the Lambda Architecture in July 2014. He kept the immutable input and the focus on reprocessing, but argued that running the same logic in two systems costs more than it saves. He suggested the name Kappa architecture for his simpler alternative.
The Lambda architecture: batch, speed and serving layers
| Layer | Holds | Computes | Tools named in 2011 |
|---|---|---|---|
| Batch | The master dataset: every event, append-only | Batch views, recomputed from all data on each run | HDFS, MapReduce |
| Serving | The latest batch views, indexed for reads | Nothing; it loads each batch run in bulk | ElephantDB, Voldemort |
| Speed | Views of only the data the last batch run has not seen | Incremental updates as events arrive | Storm, Cassandra, Riak |
A query reads the batch view and the realtime view and merges them: the batch view is complete up to a few hours ago, and the realtime view covers the gap. When the next batch run finishes, the realtime state for that period is thrown away. Marz's point was that the hard parts of incremental, mutable state sit in the speed layer, and any mistake there lasts only until the next batch run replaces it. His post calls it the realtime layer; most later writing, including his book with James Warren, says speed layer.
The price is that every metric is implemented twice, as a batch job and as a stream job in different frameworks, and the query layer needs merge logic for each view. When the batch views are fact tables in a star schema, the realtime views need the same grain and dimension keys so that the two can be combined.
The Kappa architecture: one stream job and a replayable log
Kappa removes the batch layer. All input goes to a durable, replayable log such as Kafka, the same kind of event log an event-driven architecture is built around, and one stream processing job computes the views. Lambda reprocesses by rerunning the batch layer; Kappa reprocesses by replaying the log:
- Keep the input in the log for as long as you may need to reprocess it. Kreps's example is 30 days of retention for up to 30 days of reprocessing.
- When the code changes, start a second instance of the job that reads from the beginning of the retained data and writes to a new output table.
- When the new job has caught up, switch the application to read the new table.
- Stop the old job and delete the old table.
Both tables exist during the switch, so rollback means pointing reads back at the old table. Kreps notes that this needs about twice the output storage for the duration, and a serving database that can take the write volume of a replay.
Lambda vs Kappa at a glance
| Lambda | Kappa | |
|---|---|---|
| Code paths | Two: a batch job and a stream job | One stream job |
| Source of truth | Master dataset in a file system or object store | The log, for as long as it retains data |
| Fresh results | Speed layer, merged with batch views at query time | The stream job's output table |
| Reprocessing | Every batch run recomputes from all data | Replay the log into a new table, then switch |
| Late or corrected data | Picked up by the next batch run | Event-time windows and updates in the sink |
| Main cost | Keeping two implementations equal | Retention and replay throughput |
| Typical failure | Batch and realtime numbers disagree | Retention too short to rebuild a view |
Reprocessing: the real difference
Both designs assume code will change and results must be recomputed. They differ in how often and how.
Lambda recomputes on a schedule. Every batch run rebuilds the views from the full master dataset, so a fix to the batch code reaches all history on the next run. The cost is that the batch layer runs all the time, whether or not anything changed.
Kappa recomputes on demand. The live job processes only new events, and a full recomputation happens only when you deploy a new version and replay. That makes reprocessing an operation you plan: replaying 30 days of a busy topic can take hours, competes with live consumers for broker capacity, and writes a full copy of the output. Measure replay throughput before you need it, and size the serving database for it.
How long the log must keep data
Kappa works only if the log still holds the events you need to replay. Kafka's defaults are not set for that: according to the topic configuration reference, a topic deletes segments older than seven days (retention.ms = 604800000), has no size limit (retention.bytes = -1) and uses cleanup.policy = delete.
| Option | What it keeps | Good for replaying |
|---|---|---|
| Time-based retention, 7 days by default | Every event inside the window | Views over that window only |
retention.ms = -1 |
Every event, on broker disks | Full history, at broker disk cost |
| Log compaction | At least the latest value per key | Current state per key, not counts or sums |
| Tiered storage | Recent segments on brokers, older ones in object storage | Long history at object storage cost |
| Archive to a lake table | Everything, in Iceberg or Delta tables | Long history, read by a job that scans the table |
Compaction is a common trap: a compacted topic can rebuild a table of current values, but a job that counts or sums events cannot be replayed from it. Tiered storage (KIP-405) has been production-ready since Kafka 3.9, released in November 2024. It is enabled per topic, needs remote.log.storage.system.enable=true and a RemoteStorageManager plugin for your object store on the brokers, and does not support compacted topics:
# Brokers: remote.log.storage.system.enable=true and a RemoteStorageManager plugin.
# Keep 90 days in total, of which 1 day stays on broker disks.
kafka-topics.sh --bootstrap-server kafka:9092 --create \
--topic orders.events --partitions 12 --replication-factor 3 \
--config retention.ms=7776000000 \
--config remote.storage.enable=true \
--config local.retention.ms=86400000
Correctness: event time, late data and exactly-once
One argument for Lambda was that stream processing is approximate and batch is exact. Kreps disagreed: a stream processor can give the same semantic guarantees as a batch system, if you use the right features:
- Event time, not processing time. A replay processes days of events in hours, so logic based on the wall clock gives different results on replay. The Dataflow model paper (VLDB 2015) separates event time from processing time and uses watermarks and triggers for windows over out-of-order data. Apache Beam implements that model, and Flink uses the same concepts.
- Late data. In Lambda, an event that arrives a day late is simply part of the next batch run. In Kappa, a window must stay open for late events, and the sink must accept updates to results it already wrote, so write by key with upserts instead of appending.
- Exactly-once output. With the Kafka sink set to exactly-once, Flink writes in Kafka transactions committed on each checkpoint, and consumers must read only committed data (
isolation.level=read_committed). Delta Lake uses its transaction log to give streaming writes exactly-once semantics.
Modern alternatives
Three changes have made the trade-off less sharp:
- One engine for both modes. Flink runs the same DataStream program in STREAMING or BATCH execution mode, and on bounded input both give the same final result. Apache Beam offers one programming model for batch and streaming, and in Spark Structured Streaming you write a streaming query the same way as a batch query on static data. You keep a batch backfill without a second implementation, which was Lambda's main cost.
- Table formats as long-term history. Kafka keeps days of events; an Iceberg or Delta table on object storage keeps years at lower cost, and engines can read it as a stream or as a batch table. A common shape is Kafka for recent days, a raw bronze table for history, and streaming jobs that build cleaned and aggregated tables; see the medallion architecture diagram. Loading raw data first and transforming it later is the ELT side of the choice between ETL and ELT.
- Backfill from the table with the streaming code. Uber's sessionization pipeline (2020) reads a Hive table as a streaming source in Spark for backfills, so the same streaming job processes days of history in event-time order without replaying it through Kafka.
Whichever design you choose, change data capture can feed it: it puts database changes into the log without dual writes from services; see the change data capture diagram.
Choosing between them
- Choose Kappa when one stream job can express all the logic, you can keep or archive the input for as long as you may need to recompute, and a replay finishes in a time you can accept.
- Keep a batch path when some logic needs passes over the whole dataset, such as model training or a month-end close over a fixed dataset. Use the same engine and code where you can.
- Avoid two hand-written implementations of the same metric. If you must keep them, compare their output on the same input and alert when the numbers differ.
The Lambda vs Kappa diagram
Diagram contents
- Lambda: a batch layer and a speed layer, merged at query time
- Kappa: one stream job; reprocess by replaying the log
- Event producers
- Immutable master dataset, kept forever
- Batch job
- Batch views (serving layer)
- Stream job
- Realtime views (speed layer)
- Query service
- Kafka log: 90 days (tiered storage)
- Stream job v1
- Output table v1
- Stream job v2
- Output table v2
- append
- same events
- read all data
- replace, every few hours
- incremental
- batch view
- recent delta
- live offsets
- replay from offset 0
- upsert
- reads today
- switch when caught up
How to read it:
- Left: one set of event producers, so both frames start from the same input.
- Lambda frame, blue: the batch path. Events are appended to an immutable master dataset that is kept forever, and the batch job rebuilds the batch views from all of it every few hours.
- Lambda frame, orange: the speed path. The same events go to a stream job with the same logic, which keeps realtime views for the hours the last batch run has not reached. The query service merges both.
- Kappa frame, green: the live path. Stream job v1 reads new offsets from the Kafka log, which keeps 90 days with tiered storage, and upserts output table v1, which the query service reads.
- Kappa frame, purple and dashed: a reprocessing run. Stream job v2, with the new code, replays the log from offset 0 into table v2. Once it catches up, reads switch to v2 and v1 is removed.
Drawing Lambda and Kappa diagrams clearly
- Give each path one color from source to query.
- Label retention on the log and the master dataset: 7 days, 90 days with tiered storage, or forever. It decides how far back you can recompute.
- Put the version in the name, such as job v1 and table v2, and draw a reprocessing run dashed, so the diagram shows how a change rolls out.
- Show where results merge or switch: the query service in Lambda, the cutover edge in Kappa.
- Write event time or processing time on windowed jobs, with the allowed lateness.
Common mistakes are a Kappa log with no retention label, one box called "stream processing" that hides which jobs exist, and merge logic with no owner. Draw brokers and partitions separately, as in the Kafka architecture diagram; for the flow from source databases to dashboards, see the data pipeline architecture diagram.
Build it in Archboard
- Sign in with Google or GitHub and create a diagram.
- Add two Core Frame nodes, one above the other, labeled Lambda and Kappa, each with a one-line summary.
- To the left of both frames, add a C4 Model Software System named Event producers.
- In the Lambda frame, add a Data pack Object Store for the master dataset, C4 Model Container nodes for the batch job, the stream job and the query service, and two C4 Model Database nodes for batch views and realtime views. Color the batch path blue and the speed path orange.
- In the Kappa frame, add a Data pack Kafka node for the log, with its retention in the label, two Container nodes for stream jobs v1 and v2, two Database nodes for the output tables and a Container for the query service. Color the live v1 path green, and draw the v2 path purple and dashed.
- Label the edges with what they carry, such as append, replay from offset 0 and switch when caught up, and add a Core Text note at the bottom of each frame.
If you already describe the pipeline as a Mermaid flowchart, the Mermaid converter turns it into a first draft, and the event-driven architecture template is another starting point. The example uses 15 diagram nodes, the most the Free plan allows in one diagram; the two notes are text, which has its own, larger limit.
FAQ
What is the difference between Lambda and Kappa architecture? Lambda runs a batch pipeline and a stream pipeline side by side and merges their results at query time. Kappa runs only a stream pipeline and recomputes by replaying a retained log into a new output table.
Is the Lambda architecture outdated? Its original form, with two separate implementations of the same logic, is costly to keep correct, and engines that run one program in both modes remove most of the reason for it. Keeping immutable input and recomputing from it is still good practice.
How long should Kafka retain data for a Kappa architecture? At least as far back as the oldest result you may need to recompute, plus margin for the time a replay takes. For months or years, use tiered storage or archive the topic to a lake table and backfill from there.
Can I build a Kappa architecture without Kafka? Yes. The pattern needs a durable, ordered log that several readers can replay from a chosen position, and Kreps notes it is not tied to Kafka. Some teams use a lake table as the replay source instead.