Lambda architecture

On this page 7

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.

LayerMain responsibilityTypical latencyTypical technology
Batch layerStore raw events and recompute full viewsHoursHadoop MapReduce, Apache Spark
Speed layerUpdate views for recent events onlySeconds or lessApache Storm, Apache Flink, Spark Streaming
Serving layerIndex views and merge results for queriesMilliseconds per queryApache Druid, Cassandra, HBase
The three layers of Lambda architecture

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.

ParameterTypical rangeWhat it affects
Batch recomputation interval1 to 24 hoursSize of the speed layer window and compute cost
Speed layer retentionOne to two batch intervalsMemory use and overlap safety
Master dataset retentionMonths to indefiniteStorage cost and reprocessing depth
View merge strategySum, union or overrideCorrectness of combined query results
Key design parameters and their effects

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.

ApproachCode pathsReprocessing methodMain weakness
Lambda architectureTwo, batch and streamingRerun batch jobs on raw historyDuplicate logic that must stay consistent
Kappa architectureOne, streaming onlyReplay the retained event logNeeds long log retention and a robust stream engine
Pure batchOne, batch onlyRerun jobsNo fresh results between runs
Lambda, Kappa and pure batch processing

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.

SituationRecommended choiceReason
Results must reconcile exactly with recordsLambda architectureBatch recomputation provides audited totals
Stream engine already guarantees exactly-onceKappa architectureOne code path is cheaper to maintain
Freshness of hours is acceptablePure batchSimplest operation and lowest cost
Historical logic changes oftenLambda or Kappa with long retentionFull reprocessing must stay possible
Decision guide for choosing an architecture

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.