Theory · Page 28 of 34 · Pipeline patterns

28. The Lambda architecture: two paths and their cost

Lambda runs two paths over the same data: a batch layer that recomputes everything correctly from the full history on a schedule, and a speed layer that streams for fresh results in between; a serving layer combines them. It is fast and, by morning, right. Its cost is that every piece of logic lives in two code paths, which must be written, tested and kept consistent twice.

A fast path, a correct path, and the gap between them
Playback speed

The clip feeds the morning's ten claims to a speed layer that streams them and a batch layer that recomputes everything at night. The speed layer's code was written separately and never learned the currency rule, so the travel claim counts in pounds. During the day the serving layer shows the speed view, short of the right total; the dashboard and the finance report disagree. At night the batch layer recomputes with the right code and the serving layer is right again. Last, the cost: each rule written twice, tested twice, and two answers to one question until the batch runs.

The intuition: a sketch in the morning, the drawing at night

Harbour Mutual's call-centre manager wants the value of today's claims on a screen, minutes old. The finance director wants a figure she can sign, computed the way finance has always computed it, from everything, every night. Lambda gives each what they asked for by building both: a quick sketch during the day and the careful drawing at night, which replaces the sketch.

The trouble is that the sketch and the drawing are made by different hands. When the drawing's rules change, someone must remember to change the sketch's too. One morning they do not, and the screen and the report disagree by a small amount nobody can explain.

Remember Lambda gives fresh results from a speed layer and correct ones from a batch layer; every rule is then kept in two code paths.

How it works, step by step

The batch layer keeps the master dataset, every event ever received, immutable, and on a schedule recomputes the batch views from all of it. Because it recomputes from scratch, any mistake in a view is fixed by fixing the code and running it again.

The speed layer processes only the events since the last batch run, as a stream, and keeps real-time views. They are fresh and may be approximate, and they are thrown away when the next batch view covers their period.

The serving layer answers a query by combining the two: the batch view up to the last batch run, plus the real-time view since. Here today's events all came after last night's batch, so until tonight the serving layer shows the speed view alone.

The two layers implement the same logic in two code paths, usually in different tools (a batch engine and a stream engine). Every rule must be written twice, tested twice, and kept consistent: when the two disagree, readers see two answers to one question until the next batch run.

The cost of two code paths, counted Logic: every rule in two places. Testing: every rule's tests in two suites, with two sets of test data. Consistency: a change made to one path and not the other shows as a difference between the dashboard and the report, which lasts until the batch layer overwrites the speed view.

By hand

Feed the ten events to both layers. The batch layer has the three rules; the speed layer's code was written separately and validates and masks, but forgot to convert pounds.

The ten events
EventClaimPolicyReportedReached the logAmountNote
E01C-201P-100109:01:4009:02:10€1,200–
E02C-202P-100209:0409:04:50€2,400–
E03C-203P-100309:06:3009:07:45£800health details
E04C-204P-999909:0909:09:40€650–
E06C-206P-100609:14:2009:15:05€950–
E07C-207P-100709:14:5009:15:12€4,200–
E08C-208P-100809:1509:15:20€700–
E09C-209P-100909:18:3009:19:10€1,500–
E05C-205P-100509:12:1009:21:30€3,100–
E10C-210P-101009:2409:25:40€2,600–
  1. The speed layer sums the valid events without converting. What does it count for E03, and what is its total?
    Predict the result, then check it £800 counted as €800; the speed view is €17,450.
  2. At noon, what does the serving layer show?
    Predict the result, then check it The speed view alone, €17,450: nothing of today is in last night's batch view.
  3. Tonight the batch layer recomputes with the right code. What does the serving layer show then?
    Predict the result, then check it €17,570.
  4. How far apart were the dashboard and the report all day?
    Predict the result, then check it €120: the difference between £800 and €920.
  5. The pipeline has 3 rules. How many test suites does Lambda need to cover them?
    Predict the result, then check it 6: each rule in both paths.

What you found: Lambda was fast all day and right by morning; in between it was €120 short, because one of 3 rules lived in only one of its two code paths.

Why this step
Keep an immutable master dataset
Without it: The batch layer cannot recompute anything, and mistakes stay in the views.
Recompute batch views from scratch
Without it: A bug fixed in the code is never fixed in the data.
Discard real-time views once a batch covers them
Without it: Approximate figures are kept for ever beside the correct ones.
Test both paths against the same cases
Without it: The two implementations drift and nobody notices until a reader does.
People often think…
The speed layer's figures are only approximate, so differences do not matter.
In fact: Readers act on them. All day the screen was €120 short of the report, and nobody could say why.
Lambda is obsolete.
In fact: It still fits where a nightly batch must stay the book of record and someone also needs minutes-old figures; it is the cost, not the age, that decides.
One test suite covers both layers.
In fact: Two implementations need two runs of the tests: 6 suites for 3 rules.

When it fits, and when it does not

  • Fits: a batch that must stay the book of record (finance's figures) beside a fresh view for operations, and a team that can afford two implementations.
  • Does not fit: a small team, logic that changes often, or a stream that can itself be made correct and replayed (page 29).

Design notes

If you must run Lambda, share what can be shared: one library of rules called by both layers, one set of test cases run against both, and a daily check that compares the two views and alerts on any difference beyond rounding.

Why it matters

Chapter 30 runs Lambda and Kappa side by side on a late correction; this page is about what Lambda costs to own. When an organisation chooses Lambda it is choosing to maintain everything twice, and should say so in the decision.

On Azure (checked against Microsoft Learn on 24 October 2026)

  • The speed layer is typically Azure Event Hubs read by Azure Databricks Structured Streaming or Fabric Real-Time Intelligence; the batch layer is a scheduled job in Databricks or a Fabric pipeline over the lake, and Event Hubs Capture writes the events to the lake for it.

Where it goes wrong

  • A fix in one path. The batch layer is corrected and the speed layer forgotten.
  • Two teams, two truths. Each layer has its own owner and each defends its number.
  • No comparison. Nobody checks the two views against each other, so drift is found by a reader.
  • Speed views kept. Approximate figures are read after the batch has replaced them.
You can now…
  • Name Lambda's three layers and say what each does.
  • Compute what the serving layer shows before and after the batch, by hand.
  • Count the cost of two code paths in logic, tests and consistency.
  • Say when a book of record justifies running Lambda.

Check yourself

Choose an answer to each question, then press Check.

1. At noon, what does the serving layer show for today's claims?
2. How large is the gap between the speed view and the right total?
3. What is Lambda's main cost?
Answer every question first.

Sources

The works this page draws on, summarised in its own words rather than quoted. Read them for the full argument.

  • N. Marz and J. Warren, Big Data: Principles and Best Practices of Scalable Realtime Data Systems (Manning, 2015)The batch, speed and serving layers and the immutable master dataset.
  • J. Kreps, "Questioning the Lambda Architecture" (2014)The cost of keeping the same logic in two systems.

Practise it

The chapters that put this theory to work on Harbour Mutual and Kestrel:

The tools to try it in:

  • Pipeline patterns lab · Run the same claim events through eight pipeline patterns and see latency, overhead, a consumer failing, a delivery repeated and a logic change replayed.
  • 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: Serving layer

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.