The lakehouse of the previous lesson answers the question of where the data lives. Another one remains, which concerns processing: how to combine an exact history with newly arrived data. A batch process calculates complete, reliable figures, but hours late; a continuous streaming process responds in seconds, but with data that may still be corrected, arrive late or be repeated. When a business needs both at once, it takes an architecture that reconciles them.
The two classic proposals are the Lambda architecture and the Kappa architecture. This lesson explains the problem they solve, how each one works, their advantages and drawbacks, how the landscape has evolved with unified engines and what criteria to use when choosing. The concepts of stream processing (windows, watermarks, delivery guarantees) were covered in lesson 04-03 and are taken as known here. We will finish by verifying something worth being able to state precisely: DataCorp's design is neither Lambda nor Kappa, and we will see why and how it would evolve toward one or the other.
The problem: historical accuracy and low latency
Let's take a simple question about DataCorp's clickstream: how many times has a product been added to the cart? There are two ways to answer it.
| Batch calculation | Streaming calculation | |
|---|---|---|
| How | Every night all the day's events are scanned | Each event increments a counter as it arrives |
| Latency | Hours | Seconds |
| Accuracy | High: it sees all the events, including late ones; it deduplicates at leisure | Lower: late or repeated events can throw the counter off |
| Correcting a logic error | Easy: you fix it and recalculate | Hard: the counter has already absorbed the events |
| Cost and complexity | Low | High: a permanent, stateful process |
Neither is enough if you ask at the same time for an exact, recomputable history (for the reports) and the data of the last few seconds (to act on). Lambda and Kappa are two answers to that twofold demand.
Lambda architecture
The Lambda architecture, proposed by Nathan Marz around 2011, starts from one idea: do both things in parallel and put the results together at query time. Every incoming event is sent down two paths.
flowchart LR
E["Events<br/>add_to_cart"] --> M["Event log"]
M --> B
M --> V
subgraph LB["Batch layer"]
B[("Master dataset<br/>immutable, the entire history")] --> PB["Periodic recomputation<br/>(every night)"]
end
subgraph LV["Speed layer"]
V["Streaming process<br/>recent data only"]
end
subgraph LS["Serving layer"]
VB["Batch view<br/>exact, up to last night"]
VV["Speed view<br/>approximate, since last night"]
end
PB --> VB
V --> VV
VB --> Q["Query:<br/>batch + speed"]
VV --> Q
| Layer | What it does | Property |
|---|---|---|
| Batch layer | It stores all the events in an immutable master dataset and periodically recomputes the views from it | Exact, complete and recomputable; slow |
| Speed layer | It stream-processes only the events that have arrived since the last recomputation | Fast; approximate and provisional |
| Serving layer | It exposes the two views and combines them when answering | It hides from the consumer the existence of two paths |
With the cart example: at 11:30 on November 18, the batch view contains the exact counts up to the end of the 17th, calculated in the early hours. The speed view contains today's counts, updated event by event. The query "added to cart in the last week" adds six and a half days from the former and a few hours from the latter. Tonight, the batch recomputation will incorporate the 18th accurately and the speed view for that day will be discarded: the provisional always ends up replaced by the exact.
Advantages
- Tolerance of human error. The master dataset is immutable; any logic error is fixed and recomputed from the origin.
- The best of each mode: the accuracy of batch and the latency of streaming.
- The speed layer can be simple and imperfect, because its results expire within hours.
The big drawback: the double logic
The same business rule is implemented twice, in two technologies, and has to give the same result:
- In the batch layer, "count the add-to-cart events" is a SQL query that deduplicates by
event_id. - In the speed layer, it is a program that increments counters and manages state.
Every change of definition has to be made, tested and deployed in both places. Sooner or later they diverge, and then the figure at 23:59 and the one at 00:01 do not match. It is the same problem of the duplicated definition that DataCorp eliminated with RQ-11, reappearing inside the platform itself. On top of that comes operating two different systems.
The serving layer: merging the two views
The following program shows, with minimal data, how the serving layer combines the views. It is not production code: it serves to show the mechanism and where the risk hides.
# Serving layer of a Lambda architecture: count of 'add_to_cart' events.
from datetime import date
# --- BATCH view: recomputed in the early hours from the master dataset. ---
# Exact and deduplicated. Covers up to and including 'batch_cutoff'.
batch_view = {
date(2026, 11, 15): 61_240,
date(2026, 11, 16): 58_910,
date(2026, 11, 17): 60_050,
}
batch_cutoff = date(2026, 11, 17)
# --- SPEED view: maintained by the streaming process, event by event. ---
# It only contains the days after the cutoff. Provisional.
speed_view = {
date(2026, 11, 18): 27_300, # today so far
}
def process_event(event):
"""Speed layer: runs for each event that arrives."""
if event["type"] != "add_to_cart":
return
day = event["event_time"].date()
if day > batch_cutoff: # anything earlier is already covered by the batch view
speed_view[day] = speed_view.get(day, 0) + 1
def query(date_from, date_to):
"""Serving layer: combines the two views without the user noticing."""
total = 0
for day, count in batch_view.items():
if date_from <= day <= min(date_to, batch_cutoff):
total += count # exact stretch
for day, count in speed_view.items():
if max(date_from, batch_cutoff) < day <= date_to:
total += count # provisional stretch
return total
print(query(date(2026, 11, 16), date(2026, 11, 18)))
# 58,910 + 60,050 + 27,300 = 146,260
def publish_new_batch(new_view, new_cutoff):
"""When the nightly recomputation finishes: the exact replaces the provisional."""
global batch_view, batch_cutoff
batch_view, batch_cutoff = new_view, new_cutoff
for day in [d for d in speed_view if d <= new_cutoff]:
del speed_view[day] # the speed view for those days expiresWhat is worth noticing:
batch_cutoffis the key piece. It is the boundary between what each view answers. If the two views overlap, events are counted twice; if they leave a gap, events are lost. Moving that boundary (publish_new_batch) has to be an atomic operation.queryhides the duality. The user asks for a range and gets a number; they do not know that one part is exact and another provisional. A good serving layer should say so.- The double logic is in plain sight.
process_eventcounts events without deduplicating; the batch view, by contrast, is calculated with SQL that removes the repeatedevent_idvalues. If the messaging system delivers an event twice ("at-least-once" delivery), the speed view will overcount. The 18th will show 27,300 at noon and the nightly recomputation may say that at that time it was 27,180. That discrepancy is inherent to Lambda.
Kappa architecture
The Kappa architecture, proposed by Jay Kreps in 2014, is a reaction to the double logic. Its thesis: if the streaming engine is good enough, the batch layer is unnecessary. Everything is treated as a stream, with a single path and a single codebase.
flowchart LR
E["Events"] --> R[("Event log<br/>source of truth<br/>long retention")]
R --> P1["Streaming process v1"]
P1 --> T1["View v1"]
R -. "reprocess: reread from the start" .-> P2["Streaming process v2<br/>(corrected logic)"]
P2 -.-> T2["View v2"]
T1 --> Q["Query"]
T2 -. "replaces v1 when it catches up with the present" .-> Q
Its three principles:
- Everything is a stream. A batch is nothing more than a bounded stream. The same program processes the events from a year ago and those from a second ago.
- The event log is the source of truth. There is no separate master dataset: the log (a Kafka topic or equivalent) keeps the events, ordered and immutable, for as long as necessary.
- Reprocessing means rereading the log. To correct the logic, a new version of the process is deployed, which reads the log from the beginning and builds a new view. When it catches up with the present, the queries switch to the new view and the old one is removed.
Advantages
- A single logic, a single codebase, a single processing technology. The divergence between layers disappears.
- Low latency for everything, not just for recent data.
- A conceptually simpler architecture.
Drawbacks
| Drawback | What it implies |
|---|---|
| Retention | The log has to keep all the history you want to be able to reprocess: months or years of events, not days |
| Cost | Long-term storage in the log is more expensive than in object storage, unless the service offers tiered storage. Reprocessing years of events requires a lot of compute for a while |
| Operational complexity | Everything depends on permanent, stateful streaming processes that have to be monitored 24 hours a day. Reprocessing means keeping two versions running in parallel |
| Fit with historical analysis | Joins between large histories, recomputations spanning several years or exploratory queries are better expressed and run in batch |
| Skills | Stateful stream processing is harder than batch SQL |
Lambda, Kappa and batch with micro-batches
The comparison is missing the most frequent option in practice, which is neither of the two: processing in batch and, where necessary, in micro-batches.
| Lambda | Kappa | Batch + micro-batches | |
|---|---|---|---|
| Processing paths | Two (batch and speed) | One (streaming) | One (batches of different frequencies) |
| Minimum latency | Seconds | Seconds or less | Minutes |
| Source of truth | Master dataset in cheap storage | Event log | Raw zone in cheap storage |
| Business logic | Duplicated | Single | Single |
| Reprocessing | Recompute in the batch layer | Reread the log with a new version | Rerun the batch (backfill) |
| Accuracy of recent data | Provisional until the next batch | That of the streaming engine | That of the batch: exact, but delayed |
| Operational complexity | High: two systems | High: permanent stateful streaming | Low |
| Cost | High | Medium or high | Low |
| When it fits | Large, exact history plus a real need for seconds | Data that is natively streaming and an expert team | No requirement below a few minutes |
Current evolution: unified engines and incremental tables
The debate between Lambda and Kappa has lost its edge because technology has attacked the flaw in each one.
- Unified engines. Today's engines (Spark with Structured Streaming, Flink, Apache Beam) let you write the logic once and run it in both batch mode and streaming mode. The structure of Lambda is kept, if needed, without its double code.
- The lakehouse as the destination of both modes. Tables in an open format (lesson 06-04) accept streaming and batch writes on the same table, with transactions. There are no longer two stores to merge at query time: the serving layer is a single table, and time travel and MERGE make it possible to correct the provisional data.
- Incremental tables. Several services offer tables that are declared with a SQL query and that the engine keeps up to date on its own, processing only what is new (streaming tables, dynamic tables, incremental materialized views). Whoever uses them declares the result and the desired freshness; the engine decides whether that requires a micro-batch every minute or a continuous stream.
- Tiered storage in the event log. Messaging services can offload old events to object storage without ceasing to serve them, which makes the long retention Kappa requires cheaper.
The trend is clear: a single logic, expressed declaratively, on a single storage layer, with latency as a parameter and not as a different architecture. The names Lambda and Kappa are still useful as vocabulary for describing how many paths a system has.
Selection criteria
Before choosing, these questions have to be asked in order:
- Is there any latency requirement below one minute, with a decision that takes advantage of it? If not, batch and micro-batches. It is the question from lesson 04-03, and most organizations stop here.
- Is the data born as events and is almost all consumption in real time? Then Kappa is natural (monitoring, telemetry, event platforms).
- Is there a large history with heavy recomputations and, in addition, a specific need for seconds? Then a two-path scheme, if possible with a unified engine so as not to duplicate the logic.
- Can the team operate streaming processes 24 hours a day? If not, the answer to questions 2 and 3 becomes "not yet", or a managed service.
- How far back do you need to be able to reprocess? It determines the retention of the log (Kappa) or of the master dataset (Lambda).
Application to DataCorp
Neither Lambda nor Kappa
ADR-010 set daily batches and micro-batches (stock levels every 10 minutes, clickstream every 15), with no continuous streaming engine. Let's compare it with the definitions:
| Trait | Lambda | Kappa | DataCorp (ADR-010) |
|---|---|---|---|
| Two paths for the same data? | Yes | No | No: each event follows a single path (topic → raw → cleansed → consumption) |
| Continuous streaming engine? | Yes, in the speed layer | Yes, for everything | No |
| Source of truth? | Master dataset | Event log | Raw zone (ADR-002); the topic only retains 7 days |
| Merging of views at query time? | Yes | No | No: the consumption tables are read directly |
It is not Lambda, because there is no speed layer or double logic: the funnel is calculated with a single SQL query over the cleansed events. It is not Kappa, because the event log is not the source of truth and reprocessing is not done by rereading it: it is done by repeating the batch from the raw zone, with the orchestrator's backfill. It is batch and micro-batch processing on a lakehouse, the simplest option that meets RQ-04, and it needs no other name than that.
It does have two traits in common with both, and they are the ones worth keeping: an immutable origin from which everything can be recomputed (like Lambda's master dataset) and an event log between the producers and the platform (as in Kappa).
If a requirement of seconds appeared
Let's suppose two future requests: recommendations during the session ("people who have just viewed this also buy...") and payment fraud detection. Both meet the ADR-010 condition for reconsidering continuous streaming.
What DataCorp already has in place:
| Existing piece | Why it helps |
|---|---|
Topic clickstream.events on a Kafka-compatible service |
A new consumer is added as another consumer group, without touching the website or the current collector |
Partition key customer_id |
The events of the same customer arrive in order: the basis for per-session state |
event_id in each event |
It allows deduplication under "at-least-once" delivery |
Event time in the event_time field |
It allows windows by event time |
| Raw zone with 13 months of events | History for training, validating and reprocessing |
| Iceberg tables (ADR-015) | They accept streaming and batch writes on the same table |
What would be missing: a managed streaming engine; a low-latency store to serve the result to the website (probably key-value, which would reopen the decision of lesson 02-02); continuous operation, difficult with two people (RQ-13); and the anonymous visitor identifier, a gap already noted in lesson 05-05. For fraud, moreover, payments do not go through the clickstream: orders would have to be published as events, with the change data capture that ADR-007 deferred.
There are two paths of evolution:
flowchart TB
T["Topic clickstream.events"] --> A1["Current collector<br/>micro-batches every 15 min"]
A1 --> LH[("Lakehouse<br/>raw → cleansed → consumption")]
T --> N1["NEW: streaming consumer<br/>session signals"]
N1 --> KV[("NEW: low-latency store")]
KV --> W["Website: recommendations"]
LH -. "model and historical aggregates" .-> KV
- Toward Lambda (recommended evolution). A narrow speed layer is added, only for the case that needs it, as the diagram shows. The batches and micro-batches carry on as before and remain the official version of the figures. The risk of double logic is contained because the speed layer calculates signals for the website, not business metrics: nobody will compare its result with a dashboard.
- Toward Kappa. The entire clickstream would move to stream processing, writing directly to the Iceberg tables; the topic would become the source of truth, with a retention of 13 months instead of 7 days (or with tiered storage). It would mean rewriting the clickstream processes and operating continuous streaming for 99.6% of the volume. It would only make sense if most of the use cases became real-time, and today one hypothetical case is.
In both cases, orders, campaigns, inventory and tickets would stay in batch: they arrive as extractions and files, not as events. And in both cases the decision would deserve an ADR of its own. For now, ADR-010 stands unchanged.
Common Mistakes and Tips
- Adopting Lambda or Kappa without a requirement of seconds. They are solutions to a specific problem. Without it, they only add cost.
- Calling any system with batches and something more frequent "Lambda". If there is a single path and a single logic, it is not. Precision matters when talking to vendors.
- Underestimating the double logic. Two implementations of the same rule always diverge; the question is when.
- Forgetting the boundary between views. Overlaps and gaps at the cutoff are the classic source of double counts.
- Choosing Kappa with a retention of days. Without history in the log there is no reprocessing; you have to plan where you recompute from.
- Presenting the provisional as final. If a figure may change tonight, the consumer has to know.
- Tip: if you need real time, confine it to the case that requires it. A narrow speed layer can be operated; an entire streaming platform, not always.
- Tip: always keep an immutable, recomputable origin. It is what lets you correct any error, whatever the architecture.
Exercises
Exercise 1: Which architecture is it?
Classify each system as Lambda, Kappa or batch/micro-batches, and justify it:
- A vehicle telemetry platform in which all the calculations are done by a streaming engine that reads from an event log with two years of retention; to correct a calculation, a new version is deployed that rereads the log.
- A bank that calculates consolidated balances every night with SQL and, in addition, keeps the day's transactions with a streaming process; the application shows "yesterday's balance + today's transactions".
- A chain of stores that loads sales every hour with a SQL process and queries them in a dashboard.
Exercise 2: The boundary
In the serving layer program, someone changes the condition in process_event from day > batch_cutoff to day >= batch_cutoff, and the second condition in query from max(date_from, batch_cutoff) < day to max(date_from, batch_cutoff) <= day. What error appears in the query for November 16 to 18 if late events for the 17th keep arriving? What general principle does it illustrate?
Exercise 3: Does the architecture change?
For each request, state whether it forces DataCorp to abandon batch and micro-batches, and what you would do:
- Marketing wants the conversion funnel updated every 5 minutes instead of every hour.
- The website wants to show "37 people have this product in their cart right now".
- Finance wants to be able to recalculate the net sales of 2026 with a new definition.
Solutions
Exercise 1
- Kappa. A single streaming path, an event log as the source of truth with long retention and reprocessing by rereading.
- Lambda. A batch view (yesterday's balances) plus a speed view (today's transactions), merged in the serving layer.
- Batch/micro-batches. A single path of frequent batches, with no continuous streaming or merging of views.
Exercise 2
The 17th ends up covered by both views: the batch view already contains it (60,050) and the speed view starts accumulating that day's late events, which the query adds again. The total for the 16th to the 18th is inflated with each late event for the 17th: it is a double count caused by overlap. And it is hard to detect, because the difference is small.
The principle: in a two-path architecture, the boundary has to assign each point in time to exactly one view. The late events of a day that is already closed are not added in the speed layer; the next batch recomputation will pick them up.
Exercise 3
- No. Five minutes is a more frequent micro-batch: you adjust the scheduling of
clickstream_micro_batchesand of the funnel calculation, making sure that each run finishes within its interval (the ADR-010 condition) and keeping an eye on the compute cost. Before that, it is worth asking what decision will be made every 5 minutes. - Yes, for that case. "Right now" and per product requires counters updated per event and served to the website in milliseconds: a narrow speed layer over
clickstream.eventsand a low-latency store. The rest of the platform does not change. - No. It is a historical recomputation, the strong point of batch: the definition is changed in
metrics/sales.yamland in the dbt model, and the consumption tables are rebuilt from the cleansed zone. If the source data had to be reinterpreted, from the raw zone.
Conclusion
Lambda and Kappa respond to the same problem: offering at once an exact, recomputable history and data that is seconds old. Lambda solves it with two paths, an exact batch layer and a provisional speed layer, merged in a serving layer; it pays for this with a duplicated logic that tends to diverge and a delicate boundary between views. Kappa solves it with a single streaming path and an event log as the source of truth, which is reread in order to reprocess; it pays with long retention, cost and demanding operations. Unified engines, incremental tables and the lakehouse as a common destination have brought the two closer together, to the point of turning latency into a parameter rather than an architecture. DataCorp is neither one nor the other: it processes in batch and micro-batches on its lakehouse, with a single path and a single logic, and keeps the two pieces that would let it evolve, an immutable origin and the topic clickstream.events.
That completes the architectures that answer technical questions: where the data is stored and how it is processed. But beyond a certain size, what limits a data platform is not technology but organization: a central team that cannot keep up with serving the whole company. The last lesson of the module tackles the two most influential proposals for that problem, Data Mesh and Data Fabric, and closes with a summary of all the architectures studied.
