Skip to main content
← CONCEPTS / DATA ENGINEERING & PIPELINES
An end-to-end domain learning journey

Batch & Streaming Architectures
(Lambda vs. Kappa).

Modern data platforms balance freshness and correctness using Lambda (dual batch + speed layers), Kappa (single streaming log + replay), Change Data Capture (CDC), DAG orchestration with idempotent backfills, and SCD Type 2 dimensional modeling.
Start the journey7 sections· Last modified Nov 16, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When concurrent writes contend on shared state, prefer Kappa or unified Lakehouse engines (Spark Structured Streaming + Iceberg/Delta) over dual-codebase Lambda unless legacy batch and speed engines cannot be unified.

TL;DR30-second simplified summary
▾

Core Mechanics: Data platforms must serve both low-latency fresh views (seconds) and 100% accurate historical recomputations (months/years).

Visual & Structural Flow: Depicts Immutable Event Log -> Stream Engine -> Lakehouse Serving Tables (CDC / Event Log -> Flink / Spark Stream -> Iceberg / Delta -> OLAP Serving); Zero-Downtime Logic Upgrade via Parallel Consumer Replay (Kafka / Iceberg -> Job v1 (Live) -> Job v2 (Replay) -> Serving View); OLTP WAL (CDC) -> Kafka -> Iceberg Bronze/Silver/Gold Snapshots (Postgres pg_wal -> Kafka + Schema Reg -> Iceberg Bronze/Silver -> Gold Marts / OLAP).

Trade-Offs & Production: Don't adopt streaming complexity if a 15-minute batch ELT satisfies your business SLA. Modern data platforms pair Debezium CDC (streaming OLTP changes from Postgres WAL) with Kafka and a Bronze -> Silver -> Gold Iceberg Medallion pipeline.

Failure Modes & Application: Explore lakehouse medallion pipelines, late-data watermarking, and schema evolution in production.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Apache Spark Data Engineering
Apache Spark processes petabyte-scale batch and streaming data across distributed clusters using lazy DAG execution, the Catalyst query optimizer, Tungsten off-heap memory, and Adaptive Query Execution (AQE) over columnar formats like Parquet, Delta Lake, and...
Full walkthrough · 7 stages
01
STAGE 01 · WHAT IT ISL4 · FUNDAMENTALS

What are Lambda and Kappa Architectures.

Why this matters: The mechanism: understand how Lambda and Kappa Architectures works from first principles.

Data platforms must serve both low-latency fresh views (seconds) and 100% accurate historical recomputations (months/years). Two canonical architectures solve this:

  • Lambda Architecture: Splits ingestion into an immutable Batch Layer (Spark/SQL on S3 for exact historical truth), a Speed Layer (Flink/Kafka for real-time deltas), and a Serving Layer that merges both.
  • Kappa Architecture: Eliminates the separate batch codebase—everything is an append-only event stream (Kafka + tiered storage or Lakehouse). Reprocessing historical data simply spins up a new consumer group from offset = 0 (or replays Iceberg/Delta snapshots).
Unified Kappa Flow

Immutable Event Log -> Stream Engine -> Lakehouse Serving Tables

CDC / Event LogKafka + tiered…Flink / Spark StreamSingle codebase +…Iceberg / DeltaACID snapshots +…OLAP ServingClickHouse / Trino

1.Single Codebase: Kappa runs the exact same windowing and watermark logic for live streams and historical replays.

2.Event-Time Watermarks: Handles out-of-order late events using event timestamps rather than wall-clock arrival.

3.ACID Table Snapshots: Iceberg/Delta commits provide time-travel and atomic MERGE for idempotent replays.

Kappa + Lakehouse tables unify real-time freshness and historical replayability without maintaining two codebases.

02
STAGE 02 · WHY WE NEED ITL4 · FUNDAMENTALS

Why we need Stream Replay & Watermarks (and why Lambda drifts).

Why this matters: The problem: see what breaks without Stream Replay & Watermarks under real concurrency or scale.

Maintaining Lambda forces teams to write every business aggregation twice—once in batch SQL/Spark and once in streaming Flink/Java—leading to subtle metric drift between live dashboards and next-day reports.

Moving to Kappa introduces its own engineering challenges: late/out-of-order events (mobile clients offline for hours), schema evolution (Protobuf/Avro compatibility), and state-store OOMs during multi-terabyte replays from offset = 0.

Kappa Reprocessing

Zero-Downtime Logic Upgrade via Parallel Consumer Replay

Kafka / IcebergJob v1 (Live)Job v2 (Replay)Serving View1. Tail live events -> table_v12. Replay from t=0 -> table_v23. v2 catches up to live lag=04. Atomic view swap -> table_v2

Kappa upgrades business logic by backfilling a parallel v2 sink until lag hits zero, then atomically swapping serving pointers.

Engineering Decision Framework
Problem
How to implement Batch & Streaming Architectures (Lambda vs. Kappa) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When concurrent writes contend on shared state, prefer Kappa or unified Lakehouse engines (Spark Structured Streaming + Iceberg/Delta) over dual-codebase Lambda unless legacy batch and speed engines cannot be unified.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Batch & Streaming Architectures (Lambda vs. Kappa) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

Event-Time Watermarks

Track max_event_time - allowed_lateness so late mobile events update open windows cleanly or route to a late-data side output.

SCD Type 2 Lineage

Track historical dimension changes with effective_from / effective_to columns so replayed streams join against point-in-time attributes.

03
STAGE 03 · WHERE IT IS USEDL5 · APPLIED DESIGN

Where Lambda, Kappa, and Unified Lakehouse fit.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Think of Where Lambda, Kappa, and Unified Lakehouse fit as the intuition layer for Batch & Streaming Architectures (Lambda vs. Kappa): Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Select the architecture based on your latency SLA, replay volume, and team size.

ChoiceWhat it buysWhat it costs
Kappa (Kafka + Flink + ClickHouse/Iceberg)Single codebase for live + backfill; sub-second to seconds freshness.Replaying years of raw events from Kafka requires tiered storage (S3) and large RocksDB state.
Unified Lakehouse (Spark Structured Streaming + Iceberg/Delta)Same Spark DataFrame API runs continuously (trigger availableNow or 1m micro-batch) over Bronze->Silver->Gold.Micro-batch latency (seconds–minutes) is higher than pure Flink sub-100ms CEP.
Lambda (Separate Batch + Speed Layers)Useful only when legacy batch ML/billing cannot be expressed in a streaming engine.2x engineering effort, 2x compute, and constant reconciliation bugs between layers.
04
STAGE 04 · HOW IT IS MANAGEDL5 · APPLIED DESIGN

How Watermarks, Checkpoints, and Idempotent Sinks are managed.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Production streaming pipelines enforce four invariants:

  1. Event-Time Watermarking: Define explicit withWatermark("event_ts", "10 minutes") so late data doesn't hold state forever.
  2. Checkpointing + Exactly-Once Sinks: Checkpoint RocksDB/state to S3/HDFS and use idempotent MERGE or transactional Kafka-to-Iceberg commits.
  3. Schema Registry Compatibility: Enforce BACKWARD or FULL compatibility on Avro/Protobuf topics so replays can read old records.
  4. Side-Output Dead Letters: Route late/malformed events to a DLQ topic instead of crashing the stream.
Request & State Flow

How Watermarks, Checkpoints, and Idempotent Sinks are managed

CallerService EntryCore ProcessorState Store1. Submit bounded request2. Apply domain invariant3. Persist or read state4. Return verified response
# Unified Spark Structured Streaming: event-time watermark + idempotent Iceberg MERGE
from pyspark.sql import functions as F

events = (
    spark.readStream.format("kafka")
    .option("subscribe", "orders.events")
    .load()
    .select(F.from_json(F.col("value").cast("string"), schema).alias("e"))
    .select("e.*")
    .withWatermark("event_ts", "10 minutes") # bound RocksDB state size
)

agg = events.groupBy(F.window("event_ts", "5 minutes"), "merchant_id").agg(F.sum("amount").alias("gmv"))

def upsert_to_gold(batch_df, batch_id):
    batch_df.createOrReplaceTempView("updates")
    batch_df.sparkSession.sql("""
        MERGE INTO gold.merchant_gmv_5m t USING updates s
        ON t.window = s.window AND t.merchant_id = s.merchant_id
        WHEN MATCHED THEN UPDATE SET t.gmv = s.gmv
        WHEN NOT MATCHED THEN INSERT *
    """)

agg.writeStream.foreachBatch(upsert_to_gold).option("checkpointLocation", "s3://ckpt/gmv/").start()
05
STAGE 05 · ALTERNATIVESL6 · SCALE & TRADE-OFFS

Alternatives: Lambda vs. Kappa vs. Batch-Only ELT.

Why this matters: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Think of Alternatives: Lambda vs. Kappa vs. Batch-Only ELT as the intuition layer for Batch & Streaming Architectures (Lambda vs. Kappa): The trade-off: compare competing approaches across latency, consistency, and operational cost.

Don't adopt streaming complexity if a 15-minute batch ELT satisfies your business SLA.

Component Topology

Alternatives: Lambda vs. Kappa vs. Batch-Only ELT

CalleringressRouter / APIcomputeProcessorstorageState Layercontrolrequestdispatchread/write
ChoiceWhat it buysWhat it costs
Batch-Only ELT (Airflow + dbt + Snowflake)Simplest SQL-first operations, lowest cost, trivial backfills.Freshness is minutes to hours; cannot power real-time fraud or live alerts.
Kappa / Unified LakehouseOne codebase for real-time and backfill; seconds-level freshness with ACID table commits.Requires watermark tuning, checkpoint management, and schema evolution discipline.
LambdaAllows completely independent SLAs/engines for speed vs. batch accuracy.Dual-codebase drift and operational toil.
06
STAGE 06 · PRODUCTION ARCHITECTUREL7 · STAFF / PRINCIPAL

Production example: Debezium CDC -> Kafka -> Flink/Spark -> Iceberg Medallion.

Why this matters: Production architecture: see how the components compose end to end under real load.

Think of Production example: Debezium CDC -> Kafka -> Flink/Spark -> Iceberg Medallion as the intuition layer for Batch & Streaming Architectures (Lambda vs. Kappa): Production architecture: see how the components compose end to end under real load.

Modern data platforms pair Debezium CDC (streaming OLTP changes from Postgres WAL) with Kafka and a Bronze -> Silver -> Gold Iceberg Medallion pipeline. Both streaming consumers and ad-hoc Spark backfills read the exact same Iceberg snapshots.

Medallion Lakehouse

OLTP WAL (CDC) -> Kafka -> Iceberg Bronze/Silver/Gold Snapshots

Postgres pg_walDebezium CDC streamKafka + Schema RegImmutable event logIceberg Bronze/SilverDeduplicated ACID tablesGold Marts / OLAPSub-min queries + replay

1.Zero Dual-Write: CDC captures committed WAL changes directly without application dual-writes.

2.Time-Travel Replay: Iceberg snapshots allow deterministic historical reprocessing without keeping infinite Kafka brokers.

3.Idempotent Gold MERGE: Keyed MERGE upserts absorb late-arriving CDC events without duplicating rows.

CDC + Kafka + Iceberg Medallion delivers Kappa simplicity with warehouse-grade SQL and time-travel.

07
STAGE 07 · PROBLEMS SOLVED & FURTHER DEEP DIVEL7 · STAFF / PRINCIPAL

Problems solved by Batch/Streaming Design & System Design Deep Dives.

Why this matters: Applied problems: connect these internals to concrete system design and debugging scenarios.

Think of Problems solved by Batch/Streaming Design & System Design Deep Dives as the intuition layer for Batch & Streaming Architectures (Lambda vs. Kappa): Applied problems: connect these internals to concrete system design and debugging scenarios.

Explore lakehouse medallion pipelines, late-data watermarking, and schema evolution in production.

Design Trade-Off

Problems solved by Batch/Streaming Design & System Design Deep Dives

Before · Unbounded Coupling
  • No backpressure on spikes
  • Implicit shared state
  • Cascading tail latency
After · Bounded & Observable
  • Explicit capacity budgets
  • Isolated failure domains
  • Predictable p99 latency
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

What is the primary operational disadvantage of the Lambda Architecture compared to Kappa?

Recommended Learning Flow