Run a batch path and a speed path side by side, then merge their answers.
Lambda architecture answers one question with two paths at the same time: a slow, exact batch path and a fast, rough speed path. A third part, the serving layer, merges both into one answer.
Imagine you want to show "total sales today" on a dashboard. A big batch job can count every sale perfectly, but it runs every few hours, so its answer is old. A stream job can count each sale the moment it happens, but it is harder to make exact. Lambda architecture says: use both.
All new data goes into an append-only master dataset (raw events that are never changed) and, at the same time, to the speed layer. The batch layer periodically recomputes batch views from the whole master dataset. The speed layer keeps small real-time views for the data the last batch run did not see yet.
| Layer | Job | Data it sees | Speed and accuracy |
|---|---|---|---|
| Batch layer | Store the raw master dataset and recompute batch views from all of it | Everything up to the last batch run | Slow (minutes to hours) and exact |
| Speed layer | Process new events right away and keep small real-time views | Only data the batch views do not cover yet | Fast (seconds) and often approximate |
| Serving layer | Store the batch views for quick reads and merge them with real-time views | Both views | Fast reads, as exact as its inputs |
| Layer | Typical choices |
|---|---|
| Master dataset | Object storage or a distributed file system (S3, HDFS) |
| Batch layer | MapReduce, Apache Spark |
| Speed layer | Kafka Streams, Apache Flink, Spark Streaming |
| Serving layer | A fast database such as Cassandra, HBase, Druid or Elasticsearch |
A simplified day with fixed event counts. A batch run that starts at hour H reads all data before H and is ready 2 h later. Real jobs and delays vary.
| Term | Meaning in easy words |
|---|---|
| Batch layer | Recomputes exact views from all the data, on a schedule |
| Speed layer | Processes recent events fast to fill the gap before the next batch run |
| Serving layer | Stores the views and answers queries by merging them |
| Master dataset | The append-only raw data that is the source of truth |
| Batch view | A precomputed result built by the batch layer |
| Real-time view | A small, quick result built by the speed layer for recent data |
| Immutable data | Data that is only added, never changed or deleted in place |
| Recomputation | Running the batch job again over raw data, for example to fix a bug |
| Eventual accuracy | Quick answers may be off, but become exact when the batch result arrives |
| Latency | How old the data in an answer is, or how long it takes to get it |
| Cut-off point | The time or offset where the batch view ends and the speed view begins |
| Choice | We gain | We lose |
|---|---|---|
| Run the batch job more often | A smaller gap for the speed layer to cover | More compute cost |
| Run the batch job less often | Lower cost | The speed layer covers more, so more answers are approximate |
| Rough speed layer | Simple and quick to build | Visible differences when the batch result replaces it |
| Exact speed layer | Smooth results with fewer corrections | Harder logic, and it is nearly a full second code base |
| Lambda | Both exact and fresh results | Two systems and two code bases to keep in line |
| A single stream path (Kappa) | One code base and one path | Needs a log that keeps history and a stream engine you can trust |