AlgoMaster Logo

Lambda Architecture

Last Updated: January 8, 2026

Ashish

Ashish Pratap Singh

In the first chapter of this section, we explored batch and stream processing as two distinct paradigms. Batch gives you accurate results on complete data but with high latency. Stream gives you fast results but on potentially incomplete data. What if you need both?

Consider a real-time dashboard showing total revenue. Users want to see current numbers updating live, but they also need accurate end-of-day totals. Stream processing can show approximate real-time updates, but late events and edge cases mean it might miss some transactions. Batch processing captures everything but only updates once a day.

Lambda Architecture addresses this by running both systems in parallel. The batch layer provides accuracy. The speed layer provides low latency. The serving layer merges the results. You get the best of both worlds at the cost of maintaining two separate pipelines.

In this chapter, you will learn:

  • The three layers of Lambda Architecture
  • How batch and speed layers complement each other
  • The serving layer and query merging
  • Real-world implementations and trade-offs
  • When Lambda Architecture makes sense and when it does not

The Problem Lambda Solves

Many real systems need two things at the same time:

  1. Real-time updates for user-facing experiences
  2. Accurate historical results for reporting, billing, and audits

That combination is common in revenue, fraud, recommendations, IoT monitoring, and social media metrics.

The Latency-Accuracy Trade-off

If you choose only one paradigm, you usually sacrifice the other.

Stream-only

  • Fast results
  • Can be approximate
  • Late events and edge cases can cause misses or corrections later

Batch-only

  • Accurate results
  • High latency
  • Updates arrive after the batch window completes
RequirementBatchStream
Complete dataYesMaybe (late events)
Exact aggregatesYesApproximate
Real-time updatesNoYes
Handle reprocessingEasyComplex

Use Cases Requiring Both

Use CaseWhy Both?
Revenue dashboardsLive updates + accurate daily totals
Fraud detectionImmediate alerts + refined analysis
Recommendation enginesReal-time personalization + accurate models
IoT analyticsLive monitoring + historical trends
Social media metricsLive counts + accurate engagement stats

Lambda Architecture Overview

Lambda Architecture was introduced by Nathan Marz in his book "Big Data." It proposes three layers:

  1. Batch layer computes accurate views from all historical data
  2. Speed layer computes low-latency views from recent data
  3. Serving layer answers queries by merging both views

The Three Layers

LayerPurposeProcessingLatency
Batch LayerComplete, accurate resultsProcesses all historical dataHours
Speed LayerReal-time updatesProcesses recent eventsSeconds
Serving LayerMerge and serve queriesCombines both viewsMilliseconds

The Batch Layer

The batch layer processes the entire dataset to produce accurate views.

Batch Layer Process

  1. Ingest: New data appends to master dataset
  2. Process: Batch job runs on entire dataset
  3. Output: Replace batch views with new results
  4. Schedule: Repeat on schedule (hourly, daily)

Key Characteristics

CharacteristicDescription
Immutable master dataAll raw data stored permanently
Recompute from scratchEach run processes entire history
Eventually consistentResults available after job completes
Fault tolerantCan always recompute from raw data

Example: Daily Revenue Computation

Why Immutable Master Data?

Storing raw, immutable data enables:

  • Reprocessing if bugs are found
  • New analyses without re-collecting data
  • Complete audit trail
  • Schema evolution (reprocess with new schema)

The Speed Layer

The speed layer exists for one reason: users do not want to wait for batch.

It processes only the newest data and produces a real-time view that fills the gap until batch catches up.

Speed Layer Process

  1. Consume: Read events from stream (Kafka)
  2. Process: Update incremental aggregates
  3. Store: Write to real-time views
  4. Expire: Discard after batch catches up

Key Characteristics

CharacteristicDescription
Incremental updatesOnly processes new events
Eventual replacementBatch layer eventually overwrites
Approximate resultsMay miss late events
Low latencyUpdates in seconds

Example: Real-time Revenue Updates

The Speed Layer's Limited Scope

The speed layer only covers recent data:

The speed layer only needs to cover data since the last batch run.

Once the batch layer recomputes and publishes new batch views, the speed layer’s older data becomes redundant and can be cleared.

This keeps the speed layer lightweight.

The Serving Layer

The serving layer makes Lambda usable. Without it, you would have two separate systems and no clean way to query them.

What it does

  • Reads from the batch view (last complete batch output)
  • Reads from the speed view (changes since that batch)
  • Merges the two into a single response

Merge Strategy

For aggregation queries, merging is straightforward:

Serving Layer Data Stores

Serving needs stores optimized for reads. Common choices include:

Store TypeUse CaseExamples
Key-valueSimple lookupsRedis, Cassandra
DocumentFlexible schemasMongoDB, Elasticsearch
Time-seriesMetric queriesInfluxDB, TimescaleDB
OLAPComplex aggregationsDruid, Pinot, ClickHouse

What happens when batch updates

When batch completes, it overwrites the batch view:

Lambda Architecture in Practice

Full Architecture Diagram

A typical deployment looks like this:

Technology Stack Examples

ComponentOption 1Option 2Option 3
IngestionKafkaKinesisPulsar
Batch storageHDFSS3ADLS
Batch computeSparkMapReduceFlink Batch
Stream computeFlinkSpark StreamingKafka Streams
Batch servingDruidClickHouseCassandra
Speed servingRedisMemcachedCassandra

Challenges and Trade-offs

The Dual Codebase Problem

The biggest criticism of Lambda Architecture: You end up implementing the same business logic twice.

  • One implementation for batch
  • One for stream
ChallengeDescription
Duplicate logicSame transformation in two codebases
Different languagesBatch in Scala, stream in Java
Testing complexityMust verify both produce same results
Maintenance burdenEvery change requires two updates
Skill requirementsTeam needs both batch and stream expertise

Mitigating the Dual Codebase

Some approaches to reduce duplication:

ApproachHow It Helps
Unified frameworksSpark, Flink support both batch and stream
Shared librariesCore logic in reusable modules
SQL-based processingSame SQL for batch and stream
Code generationGenerate both from common definition

Operational Complexity

Running Lambda Architecture requires:

  • Maintaining two processing pipelines
  • Monitoring both batch and stream jobs
  • Managing storage for master data, batch views, and speed views
  • Handling failures in each layer independently
  • Coordinating batch completion with speed layer reset

When to Use Lambda Architecture

Good Fit

  • Mixed latency requirements: Some users need real-time, others need accurate
  • Historical reprocessing needed: Bugs require recalculating from scratch
  • Complex aggregations: Batch can compute what stream cannot
  • High data volumes: Batch efficiently processes massive datasets
  • Regulatory compliance: Immutable master data for audit

Poor Fit

  • Pure real-time: Speed layer alone might suffice
  • Simple aggregations: Stream processing handles it
  • Small team: Maintaining two systems is hard
  • Low data volume: Overhead not justified
  • Tight latency SLAs: Batch layer too slow

Decision Framework

Summary

Lambda Architecture provides both accuracy and low latency by running parallel pipelines:

  • Batch layer processes all historical data for accurate, complete results but with high latency.
  • Speed layer processes recent events for real-time updates, compensating for batch delay.
  • Serving layer merges both views to answer queries with low latency and reasonable accuracy.
  • Immutable master data enables reprocessing when bugs are found or schemas evolve.
  • Trade-off: Dual codebase maintenance is the main challenge.
  • Good fit: Systems needing both real-time updates and accurate historical analysis.
  • Evolution: Led to Kappa Architecture, which attempts to simplify by using only stream processing.