Part F · Chapter 30 · The platform on Azure, streaming and AI

30. Lambda and Kappa: architectures for streaming

Lambda runs a fast streaming layer beside a slow batch layer that overwrites it every night; Kappa runs one streaming job over a log it can replay. Both can be right in the end; they differ in when, at what cost, and in how many places the logic lives.

Two code paths drifting apart, against a single stream replayed
Playback speed

The clip reads the same claims log as a nightly batch, as Lambda and as Kappa, event by event, into fifteen-minute windows. The adjuster's correction to C-103 arrives at 09:56, after its window has closed: Lambda's speed layer and Kappa both drop it, and their first window disagrees with the truth. Kappa's corrected job then replays the log from the first event and agrees with the truth at once; Lambda waits for the nightly batch at 23:00, whose batch layer recomputes every window and overwrites the speed layer.

The idea: one log, two ways to read it

Both architectures start from an event log: every claim event kept in order, with the time it happened (event time) and the time it was read. A streaming job sums events into windows of event time and keeps each window open until its watermark (the latest event time seen, less the allowed lateness) passes the window's end; an event that arrives later is dropped.

  • Lambda runs two layers: a speed layer that streams for fresh, approximate figures, and a batch layer that recomputes everything from the log every night and wins. Late data is fixed at night. The price: the same logic written twice, in two code paths that drift apart.
  • Kappa runs one streaming job. To fix a mistake, or take in a correction after its window closed, you replay: start the corrected job from the first event in the log into a new view, and switch readers to it when it has caught up. The price: the log must be kept long enough, and a replay takes time and compute.
The log is the source of truth In both architectures the event log, not any view, is what is true. Views are computed from it and can always be computed again: this is event-driven architecture's central idea.
Remember Keep the log; choose Lambda when a nightly batch must stay the book of record, Kappa when one code path matters and the log can be replayed, and plain batch when nobody needs it sooner.

A worked example: C-103's late correction

The feed has 12 events in 4 windows. Before any fix, the streaming views are right in 3 of 4 windows: the correction was dropped. Kappa's replay makes it 4 of 4 before the batch; Lambda reaches 4 of 4 only after the batch at 23:00.

The day's outcome (computed by the Stream lab; cost in illustrative compute units)
ArchitectureRight before the batchRight after itEvents readCostCode paths
Batch0 / 44 / 4125.21
Lambda3 / 44 / 42430.42
Kappa4 / 44 / 42426.41

A replay is not free. Harbour Mutual's claims log carries about 120,000 events a day; kept for 30 days on 4 partitions, each read at 500 events a second, a replay reads 3,600,000 events in about 30 minutes, about 2.0 compute units.

Kappa's job as Spark SQL on Delta Lake: each micro-batch merged by claim, and the windowed view (replayed with Spark Structured Streaming 4.0.1 in CI)
CREATE TABLE claim_latest (claim STRING NOT NULL, event_time TIMESTAMP NOT NULL, amount INT NOT NULL, version INT NOT NULL) USING DELTA;

-- For every micro-batch read from the log (the batch is the view `updates`):
MERGE INTO claim_latest AS t
USING (
  SELECT claim, event_time, amount, version FROM (
    SELECT *, ROW_NUMBER() OVER (PARTITION BY claim ORDER BY version DESC) AS rn FROM updates
  ) WHERE rn = 1
) AS s
ON t.claim = s.claim
WHEN MATCHED AND s.version > t.version THEN UPDATE SET event_time = s.event_time, amount = s.amount, version = s.version
WHEN NOT MATCHED THEN INSERT (claim, event_time, amount, version) VALUES (s.claim, s.event_time, s.amount, s.version);

-- The serving view:
SELECT DATE_FORMAT(window(event_time, '15 minutes').start, 'HH:mm') AS window_start, SUM(amount) AS total
FROM claim_latest
GROUP BY window(event_time, '15 minutes')
ORDER BY window_start;
Try this In the Stream lab, switch on the speed layer's older code with an allowed lateness of 60 minutes: Lambda counts C-103 twice until the batch layer overwrites it.

Why it matters for Alex

The fraud team wants claims scored in minutes, finance wants figures it can sign, and adjusters correct amounts days later. Alex has to say where corrections land, how long the log is kept, and whether the company can afford two versions of the same logic. When batch is enough, saying so saves a streaming platform nobody needed.

Where it goes wrong

  • Lambda's two code paths. A fix made in the batch layer and forgotten in the speed layer: the dashboard and the morning report disagree, every day.
  • Kappa without the log. A replay needs the events: keep the log only seven days and a correction from last month cannot be replayed.
  • Lateness set by hope. Windows that close in five minutes for corrections that come in hours: the stream is wrong until someone replays it.
  • Streaming what batch would do. A monthly report built on a stream: more to run, more to break, and no reader who needed it sooner.

Exercises

The lab checks each one against facts written down in advance, so any answer the brief allows passes. A pass is kept in this browser.

A late correction, handled both ways

The adjuster's correction to C-103 arrives at 09:56, long after its window closed. Harbour Mutual's dashboard must show the right totals: Kappa's view before the nightly batch, Lambda's after it, with the speed layer running the same code as the batch layer and never counting a claim twice.

The lab checks that:

  • The late correction stays in the feed.
  • Kappa's view is right in every window before the nightly batch.
  • Lambda's view is right in every window after the nightly batch.
  • The speed layer runs the same code as the batch layer.
  • No view ever counts a claim twice.
Work it in the Stream lab
Open the brief in the Stream lab, change the settings until they meet the brief, and press Check there.

Batch, Lambda or Kappa

Which architecture fits the requirement? Pass all 3 situations to complete it.

A monthly list of large claims for the reinsurer. Amounts are often corrected during the month; nobody needs the list before month end. The team runs no streaming today.

Your choice
Your reason (one or two)

How long does the replay take?

Harbour Mutual's claims log carries 120,000 events a day, and each partition is read at 500 events a second during a replay. Estimate how long each replay takes.

7 days of the log, on 4 partitions
30 days of the log, on 4 partitions
90 days of the log, on 4 partitions
90 days of the log, on 32 partitions
365 days of the log, on 4 partitions

On Azure

Checked against Microsoft's documentation on 18 October 2026.

The streaming parts on Azure:

  • Azure Event Hubs is the log: partitions, consumer groups, and retention of up to seven days on the Standard tier and up to ninety on Premium and Dedicated. For longer, Event Hubs Capture writes the events to the lake, and a replay reads them from there.
  • Fabric Real-Time Intelligence: Eventstream reads Event Hubs and routes events, Eventhouse stores them in KQL databases for queries in seconds, and Activator acts on patterns as they happen.
  • Databricks Structured Streaming runs the Kappa job on Delta tables: a checkpoint remembers where it is in the log, and a replay is the corrected job started with a new checkpoint from the earliest offset (or from the captured files).

Batch is still the right answer for monthly and quarterly figures, for anything a finance team signs, and wherever nobody acts on the data faster than once a day.

Take it to work

Streaming architecture choice

Decide between batch, Lambda and Kappa for one feed.

The feed

  • Who reads it, and how fresh it must be
  • How late corrections arrive

The log

  • Where events are kept, and for how long

The architecture

  • Batch, Lambda or Kappa, and the reason

Corrections

  • Allowed lateness
  • Replay: how long it takes and what it costs

Book of record

  • Which view finance signs

Tools in this chapter

  • Stream lab · Run one claims feed as batch, Lambda and Kappa side by side, inject a late correction and replay the log.

Terms taught here: Lambda architectureKappa architectureEvent timeWindowWatermarkReplay

An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to the Cloud Data Architecture Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.