Lambda architecture is a data processing design that runs a batch layer and a speed layer in parallel over the same input and combines their outputs in a serving layer, so queries receive results that are both complete and recent. Streaming data pipelines adopted it in the early 2010s, when stream processors could not yet guarantee correct results on their own.
The pattern rests on one idea: keep an immutable master dataset of raw events, recompute accurate views from it periodically, and cover the gap since the last recomputation with approximate real-time views. It is closely related to, and often contrasted with, Kappa architecture, which removes the batch layer entirely.
How Lambda architecture processes data
Lambda architecture processes every incoming event twice: once through a high-latency batch path that guarantees correctness, and once through a low-latency streaming path that guarantees freshness. Events usually arrive through a message broker such as Kafka, which feeds both paths from the same event stream.
The batch layer appends each event to the master dataset, typically stored as files in a distributed file system or object storage, and periodically runs a full recomputation over all history. Because the computation starts from raw data each time, a bug fix or a logic change is corrected simply by rerunning the job. The resulting batch views are precise but are only as fresh as the last completed run, often hours old.
The speed layer handles only the events that the batch layer has not yet absorbed. It uses stream processing to maintain incremental real-time views, which are discarded once the next batch run covers the same period. The serving layer indexes the batch views and answers queries by merging batch and real-time results.
The following table summarizes the role of each layer and its typical characteristics.
| Layer | Main responsibility | Typical latency | Typical technology |
|---|---|---|---|
| Batch layer | Store raw events and recompute full views | Hours | Hadoop MapReduce, Apache Spark |
| Speed layer | Update views for recent events only | Seconds or less | Apache Storm, Apache Flink, Spark Streaming |
| Serving layer | Index views and merge results for queries | Milliseconds per query | Apache Druid, Cassandra, HBase |
Design principles behind the batch and speed layers
Lambda architecture follows a small set of principles that explain why it tolerates failures well. The most important is immutability: raw events are never updated or deleted, only appended, so the master dataset is a single source of truth from which any view can be regenerated.
- Recomputation over mutation: views are functions of all data, so errors are fixed by recomputing rather than by patching stored state.
- Human fault tolerance: a faulty deployment can corrupt real-time views, but the next batch run overwrites the damage.
- Complexity isolation: the hard problems of incremental, distributed state are confined to the speed layer, whose results are temporary by design.
- Eventual accuracy: real-time views may be approximate, for example through probabilistic counters, because the batch layer later supplies exact values.
These principles also define the key parameters a team must choose. The table below lists them with typical values and their effects.
| Parameter | Typical range | What it affects |
|---|---|---|
| Batch recomputation interval | 1 to 24 hours | Size of the speed layer window and compute cost |
| Speed layer retention | One to two batch intervals | Memory use and overlap safety |
| Master dataset retention | Months to indefinite | Storage cost and reprocessing depth |
| View merge strategy | Sum, union or override | Correctness of combined query results |
Lambda architecture compared with Kappa and micro-batch designs
Lambda architecture differs from its alternatives mainly in how many code paths compute the same result. Kappa architecture keeps one streaming path and handles reprocessing by replaying the event log from a retained offset, which became practical once engines such as Apache Flink offered exactly-once semantics, event time handling and watermarks for late data.
Micro-batch processing is not a competing architecture but an execution model; it can implement the speed layer of a Lambda system or the single path of a Kappa system. The comparison below shows where each approach fits.
| Approach | Code paths | Reprocessing method | Main weakness |
|---|---|---|---|
| Lambda architecture | Two, batch and streaming | Rerun batch jobs on raw history | Duplicate logic that must stay consistent |
| Kappa architecture | One, streaming only | Replay the retained event log | Needs long log retention and a robust stream engine |
| Pure batch | One, batch only | Rerun jobs | No fresh results between runs |
When to choose Lambda architecture
Lambda architecture is the right choice when fresh approximate answers and auditable exact answers are both required and the batch and streaming logic differ legitimately. Examples include billing, fraud scoring with offline model features, and analytics that must reconcile with financial records.
Many modern platforms reduce the duplication by writing transformations once in a unified API, such as Apache Beam or Spark Structured Streaming, and executing them in both modes. Lakehouse table formats with incremental merges blur the line further, because a single table can receive streaming inserts and periodic batch corrections.
| Situation | Recommended choice | Reason |
|---|---|---|
| Results must reconcile exactly with records | Lambda architecture | Batch recomputation provides audited totals |
| Stream engine already guarantees exactly-once | Kappa architecture | One code path is cheaper to maintain |
| Freshness of hours is acceptable | Pure batch | Simplest operation and lowest cost |
| Historical logic changes often | Lambda or Kappa with long retention | Full reprocessing must stay possible |
Limitations and common mistakes
The central criticism of Lambda architecture is the cost of maintaining two codebases that must produce semantically identical results in different frameworks. Divergence between them causes visible jumps in metrics when batch views replace real-time views.
- Logic drift: a filter added only to the streaming job makes numbers change unexpectedly at each batch handover.
- Overlap errors: counting the same events in both views because the cut-off timestamp is applied inconsistently.
- Time semantics mismatch: the batch job groups by event time while the speed layer groups by processing time.
- Operational load: two clusters, two deployment pipelines and two sets of monitoring roughly double the operating effort.
A disciplined implementation defines the handover boundary explicitly, stores the batch watermark with each view, and runs reconciliation tests that compare both paths on the same sample of events.
Put simply
Lambda architecture is like keeping two sets of books. A clerk writes down every sale the moment it happens, quickly and sometimes with small slips. Each night an accountant recounts everything from the original receipts and produces the correct totals.
When someone asks how much was sold, the answer combines last night’s careful count with today’s quick notes. The result is fast and eventually exact, but the business must pay two people to do overlapping work.
In practice
An online advertising platform must show advertisers their impressions and clicks within seconds, yet invoices must be exact. Raw click events flow through Kafka into two paths. A Flink job updates per-campaign counters every few seconds, while a nightly Spark job recomputes all counts from the raw events stored in object storage and removes bot traffic with a model that is too heavy to run in real time.
The dashboard reads both views and merges them at the last batch boundary. During the day, an advertiser sees approximate counts that run about 2 to 4 percent high because bot filtering is lighter. After the nightly run, the figures settle to the billable totals, and invoices are generated only from batch views, which gives the finance team auditable numbers without sacrificing live monitoring.