Lambda vs Kappa Diagram

Lambda and Kappa are the two classic shapes for systems that need both fresh and correct analytics. Lambda runs a batch path and a streaming path in parallel and merges them when you query. Kappa keeps only the streaming path and recomputes history by replaying a retained log. This page draws both side by side, then shows how Kappa reprocesses.

These are architecture diagrams, not UML. UML covers software structure and behaviour; boxes-and-arrows data architecture views are one of the other standard notations used alongside it.


1. The Diagram

Lambda vs Kappa, side by sideLAMBDA: two paths, merged at query timeKAPPA: one stream path, replay to recomputeEvent sourceclicks, orders, IoTMaster datasetimmutable, append-only (S3)Batch layerSpark, recompute every 6 hBatch viewscomplete, hours oldSpeed layerFlink / Storm, secondsReal-time viewsrecent data onlyServing layerquery = batch view + real-time deltaEvent sourceclicks, orders, IoTKafka logretention 30 days or infinite (tiered)Stream processorFlink, one codebaseServing storePinot / Cassandra / PostgresQueries and dashboardsalways currentreplayfromoffset 0
  1. Lambda, batch path. Every event lands in an immutable master dataset. A batch job recomputes complete views from scratch every few hours. Correct, but stale.
  2. Lambda, speed path (yellow). The same events go through a stream processor that maintains approximate views covering only the hours the batch has not reached yet.
  3. Lambda, serving. A query combines both: batch view up to the last batch run plus the real-time delta since then. When the next batch lands, the speed layer's old data is discarded.
  4. Kappa, single path. Events go into a Kafka log retained long enough (or forever, with tiered storage). One stream job writes the serving store.
  5. Kappa, reprocessing (dashed). To fix a bug or change logic, start the job again from offset 0. The log is the master dataset.

2. How to Read It

Notationbatchperiodic recomputestreamingcontinuousserving / outputwhat users querydata flowreplay / reprocess

Colour by processing mode: blue batch, yellow streaming, green what users query. The visual test is simple: count the parallel paths. Two paths means two codebases implementing the same logic, which is Lambda's main cost.

3. Variant: Kappa Reprocessing

Kappa reprocessing: run v2 beside v1, then switchKafka topic orders (retained log)offset 0headjob v2 (new logic)replays from offset 0job v1 (current)consumes at headorders_agg_v2backfillingorders_agg_v1liveorders_aggalias / viewwhen v2 catches up: point the alias at v2, stop v1, drop v1 table

Kappa replaces "rerun the batch" with "run a second copy of the stream job". Version 2 reads from the start of the log into a new table while version 1 keeps serving. When v2 reaches the head, the alias or view is repointed and v1 is stopped. This needs enough log retention, enough spare compute to read history quickly, and a sink that can be swapped atomically.

4. Pros, Cons, and When to Use

Pros

Cons

When to use

When not to use

5. As Diagrams-as-Code

D2 handles side-by-side containers well:

# D2 (d2lang.com) - render: d2 lambda-kappa.d2 out.svg
lambda: Lambda {
  src: Event source
  master: Master dataset (S3)
  batch: Batch layer (Spark)
  bviews: Batch views
  speed: Speed layer (Flink)
  rtviews: Real-time views
  serve: Serving layer
  src -> master -> batch -> bviews -> serve
  src -> speed -> rtviews -> serve
}
kappa: Kappa {
  src: Event source
  log: Kafka log (retained)
  proc: Stream processor (Flink)
  store: Serving store
  apps: Queries
  src -> log -> proc -> store -> apps
  log -> proc: replay from offset 0 {style.stroke-dash: 4}
}