Lambda Architecture
The Lambda architecture processes the same events along two paths: a batch layer that periodically recomputes accurate results from all historical data, and a speed layer that processes new events in real time to cover the gap since the last batch run. A serving layer merges both so queries get answers that are complete and fresh. Nathan Marz described it around 2011, when stream processors were not yet reliable enough to be the only source of truth.
Follow one stream of events
- Every event is appended to an immutable master dataset. The batch layer can always recompute from scratch, which makes it the source of truth.
- Every few hours a batch job rebuilds the batch view from all data. Accurate and complete, but up to 6 hours stale.
- The speed layer processes only events since the last batch run, incrementally. Fast, possibly approximate, and thrown away when the next batch view lands.
- The serving layer answers queries by merging both views: complete history plus the last few hours.
- The catch: the same business logic is written twice, in a batch engine and a stream engine, and both must give identical answers forever.
The three layers
| Layer | Job | Typical tools (then → now) |
|---|---|---|
| Batch | Store all raw data immutably, recompute views from scratch | Hadoop MapReduce → Spark on S3 / lakehouse tables |
| Speed | Process recent events incrementally, low latency | Storm → Flink, Spark Structured Streaming, Kafka Streams |
| Serving | Index views and merge them for queries | HBase, Druid, Cassandra → Druid, Pinot, ClickHouse, a warehouse |
Trade-offs
Strengths
- Batch recomputation fixes bugs and late data: correct the code, rerun, and history is right again.
- The speed layer can be simple and approximate, because its results are temporary.
- Fault tolerant: if the speed layer breaks, the next batch run still produces correct numbers.
Weaknesses
- Two codebases with the same logic in different frameworks. They drift, and debugging “why does the dashboard jump at 06:00?” is painful.
- Two systems to run, monitor and pay for.
- Merging views in the serving layer is custom logic for every metric.
Is Lambda still used?
Rarely as a deliberate design for new systems. Modern stream processors (Flink, Spark Structured Streaming) give exactly-once state and handle late events, which removes the original reason for a separate batch path. Teams now either use Kappa, or a lakehouse where streaming and batch jobs write the same tables with the same code (Spark or Flink SQL in both modes). You still see Lambda-shaped systems in practice, often by accident: a nightly batch pipeline plus a separate real-time dashboard built later.
Common mistakes
- Implementing metrics differently in the two layers so numbers change when the batch view replaces the realtime one.
- No clear handover point: the speed layer must cover exactly the events the latest batch view does not.
- Choosing Lambda when hourly freshness from a single batch pipeline would have been enough.
Learning Resources
Articles
- How to beat the CAP theorem: Nathan Marz, the original idea
- Questioning the Lambda Architecture: Jay Kreps
- Databricks: What is Lambda architecture?
Books
- Big Data: Principles and best practices of scalable realtime data systems: Nathan Marz and James Warren
- Designing Data-Intensive Applications: Martin Kleppmann