$ ./lambda --batch spark --speed flink

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

$ ./lambda --query orders_today
Two paths, merged at query time
EVENTS orders · Kafka BATCH LAYER master dataset (S3)Spark · every 6 h BATCH VIEW as of 06:001,200 orders SPEED LAYER Flink · per eventonly since 06:00 REALTIME VIEW 06:00 → now85 orders SERVING merge views 1,285 orders today = 1,200 (batch) + 85 (speed) = 1,285 same logic, two codebases
  1. Every event is appended to an immutable master dataset. The batch layer can always recompute from scratch, which makes it the source of truth.
  2. Every few hours a batch job rebuilds the batch view from all data. Accurate and complete, but up to 6 hours stale.
  3. The speed layer processes only events since the last batch run, incrementally. Fast, possibly approximate, and thrown away when the next batch view lands.
  4. The serving layer answers queries by merging both views: complete history plus the last few hours.
  5. 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

Books