Kappa architecture

On this page 7

Kappa architecture is a data processing design in which every result is computed by a single stream processing pipeline that reads from an immutable, replayable event log. In streaming data systems it replaces the separate batch and speed layers of Lambda architecture with one code path, so historical recomputation becomes a matter of replaying the log rather than running a different batch job.

The pattern was proposed in 2014 by Jay Kreps, one of the creators of Kafka, as a response to the operational cost of maintaining two codebases. It assumes that the log retains enough history, that the stream processor can handle reprocessing at high speed, and that results can be rebuilt into a fresh output table and then swapped in.

How Kappa architecture processes and reprocesses data

Kappa architecture works by treating the event log as the system of record and every downstream table as a derived, disposable view. Producers append events to a durable, partitioned log such as Kafka, Apache Pulsar or Redpanda, and one or more stream processing jobs consume those events to maintain outputs in databases, search indexes or analytical stores.

When business logic changes or a bug is found, engineers do not patch the existing output. They deploy a second instance of the job with the new code, point it at the beginning of the retained log, let it catch up to the present, and then switch consumers to the new output table. The old job and its table are retired afterward. This replay-and-swap procedure is the defining mechanism of the pattern.

The following table lists the core components and the role each one plays.

ComponentRoleTypical technology
Event logDurable, ordered, replayable history of all eventsKafka, Apache Pulsar, Redpanda
Stream processorApplies transformations, joins and aggregationsApache Flink, Kafka Streams, Spark Structured Streaming
State storeHolds keyed intermediate state for aggregationsRocksDB, embedded key-value stores
Serving layerExposes derived views to applications and analystsRelational database, OLAP store, search index
Schema registryKeeps event formats compatible across code versionsAvro, Protobuf or JSON Schema registry
Core components of a Kappa pipeline

Preconditions that make the pattern viable

Kappa architecture is viable only when the log can serve as a complete history. That requires long or infinite retention, often achieved with log compaction for keyed entities or tiered storage that offloads older segments to object storage while keeping them readable through the same consumer API.

The stream processor must also deliver reprocessing throughput far above the live ingest rate. A job that consumes at only twice the production rate needs a week to replay a week of history while live traffic keeps arriving, which is rarely acceptable. In practice, teams provision parallelism by partition count and temporarily scale workers during a replay.

Correctness during replay depends on event-time semantics. Because historical events are read much faster than they were produced, windows must be computed from timestamps embedded in the events, with watermarks bounding late data, rather than from processing time. Exactly-once semantics or idempotent sinks prevent duplicate results when jobs restart mid-replay.

RequirementWhy it mattersCommon way to meet it
Retained historyReplay needs every relevant eventCompaction or tiered storage
High replay throughputRecomputation must finish in hours, not weeksMore partitions and temporary scaling
Event-time processingReplayed windows must match live windowsEvent timestamps with watermarks
Deterministic logicTwo runs must produce the same resultAvoid wall-clock calls and external lookups
Idempotent or transactional sinksRestarts must not double-countUpserts by key or two-phase commit
Requirements and why each one matters

Kappa architecture compared with Lambda architecture

The essential difference is that Lambda architecture runs two pipelines and merges their outputs, while Kappa architecture runs one pipeline and recomputes by replay. Lambda pairs an accurate but slow batch layer with a fast but approximate speed layer; Kappa argues that a sufficiently capable stream processor can be both accurate and fast.

Neither design is universally superior. Lambda tolerates weaker streaming guarantees because the batch layer eventually corrects errors, whereas Kappa demands mature exactly-once processing and careful state management. Micro-batch processing engines can serve either design, since the distinction concerns pipeline topology rather than execution granularity.

AspectKappa architectureLambda architecture
Number of code pathsOne streaming codebaseSeparate batch and speed codebases
Source of truthReplayable event logMaster dataset in batch storage
RecomputationReplay the log into a new outputRerun the batch job
Consistency riskLow, same logic everywhereDivergence between the two layers
Operational loadOne system to run and testTwo systems and a merge step
Ad hoc historical queriesWeaker without a separate lakeStrong through batch storage
Kappa and Lambda side by side

When to choose a Kappa design

A Kappa design is the right choice when most consumers need fresh, continuously updated results and the transformations are expressible as stream operations. It fits event-driven products, operational analytics and real-time feature pipelines for machine learning, where a single definition of each metric reduces disputes about which number is correct.

It is a weaker fit when workloads are dominated by large exploratory scans or complex joins across years of data. Many organizations therefore combine a Kappa pipeline for operational outputs with a lakehouse that receives the same events for analytical queries, which keeps the single-code-path benefit where it matters most.

SituationRecommended approachReason
Low-latency dashboards and alertsKappaOne pipeline keeps metrics consistent and fresh
Frequent logic changesKappa with replayNew versions are tested against full history
Petabyte-scale ad hoc analysisBatch or lakehouse alongsideScans are cheaper on columnar storage
Short log retention onlyLambda or hybridReplay cannot rebuild old results
Strict regulatory recomputationKappa with archived logDeterministic replay provides an audit trail
Decision guide for adopting the pattern

Limitations and common mistakes

The most frequent failure is underestimating replay cost. Reprocessing months of events can saturate brokers, evict page caches and slow live consumers, so replays should run against separate consumer groups with throttling and, where possible, from tiered storage rather than hot disks.

  • Schema evolution breaks replay when old events cannot be decoded by new code; a schema registry with backward compatibility rules prevents this.
  • Non-deterministic logic, such as calls to external services during processing, yields different results on each replay.
  • Large keyed state makes job restarts slow; checkpoint sizes of hundreds of gigabytes are common and require planning.
  • Deleting data for privacy conflicts with an immutable log; compaction with tombstones or crypto-shredding is needed to honor erasure requests.

Stripped to the essentials

Imagine a shop that writes every sale into one notebook and never erases anything. Any report the shop needs, such as daily totals or best-selling items, is worked out by reading that notebook. If the shop discovers that a report was calculated wrongly, it simply reads the notebook again from the first page with the corrected method and replaces the old report.

That is the whole idea of Kappa architecture. One recorded history and one way of processing it replace two separate systems that might disagree. The cost is that the notebook must be kept for a long time and reread quickly when needed.

Where it is applied

A mid-sized ride-hailing company streams trip, pricing and driver events into a Kafka cluster with 64 partitions and tiered storage that keeps 18 months of history. A single Apache Flink job computes per-city earnings, surge statistics and driver utilization, writing results into an analytical database that powers both operations dashboards and weekly finance reports.

When the finance team changes how cancellation fees are attributed, engineers deploy a second Flink job with the new rule, replay the full 18 months at roughly 40 times the live rate, and complete the backfill in about 11 hours. After comparing totals, they switch the dashboards to the new table and stop the old job. The outcome is one consistent set of numbers for operations and finance, without maintaining a separate batch codebase.