SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
  • Batch vs Stream Processing
  • Change Data Capture (CDC)
  • MapReduce
  • ETL Pipelines
  • Data Lakes
  • Data Warehousing
  • Data Lakehouse
  • Lambda Architecture
  • Kappa Architecture
  • Streaming Engines
  • Spark and Hadoop
  • Workflow Orchestration (Airflow)
  • Parquet and Columnar File Formats
  • Data Governance and Feature Stores
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Advanced Data Topics/Big Data Processing

Kappa Architecture

Use only a stream path, and replay the log when you need to recompute.

⏱ 12 min readAdvancedInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Kappa architecture keeps just one path for data: a stream job that reads from a log. When you need to recompute (for example to fix a bug), you do not run a separate batch job. You replay the log through a new version of the same job.

  • All data goes into a durable, ordered log (for example Apache Kafka) that keeps history.
  • One stream-processing job turns the log into views (tables, indexes, counters).
  • To change the logic, start v2 of the job, replay the log into a new view, and switch users over when it catches up.

02Concept: What is it?

Lambda architecture needs two code bases: one for batch and one for streaming. Kappa asks a simple question: what if the stream job could also do the work of the batch job? If the log keeps all the events, then "batch" is just a stream job that starts reading from the beginning of the log instead of the end.

The log is the heart of the design. It is append-only and ordered, and consumers keep their own offset (their place in the log). A new consumer can start at offset 0 and read everything again. Because there is one code path, there is no second system to keep in line.

One path, with replay
πŸ“₯Eventsproducers
→↓
πŸͺ΅Logordered, keeps history
→↓live
βš™οΈJob v1serving now
→↓
πŸ—‚οΈView v1
⇒⇣replay from start
βš™οΈJob v2new logic
⇒⇣
πŸ—‚οΈView v2building
→↓then switch
πŸ‘₯Users
v1 serves users today. v2 reads the same log from the start. When v2 has caught up, the switch is a small change.
🧠The log is the source of truth
In Kappa, the views are disposable. If they are wrong, you throw them away and rebuild them from the log. This only works if the log keeps enough history and the job is deterministic (the same events give the same result).

03Real-Life Example

🍡The Bank Statement Rebuilt from Receipts
A shop keeps every receipt in one long, numbered roll, and never removes any. The accountant keeps a running total on a sheet of paper as the receipts come in. One day the shop notices the accountant has been adding refunds instead of subtracting them. The fix is easy: a new accountant starts with a clean sheet, reads the roll from receipt number 1 using the correct rule, and catches up with the live total. Once the new sheet matches today's receipt, everybody starts using it, and the old sheet is thrown away. But if the shop threw away the oldest receipts to save space, the new accountant cannot get the right total.
Receipt roll
Kappa architecture
The numbered roll of receipts
The log of events
Receipt number 1, 2, 3...
Offsets
The accountant's running total
A view built by the stream job
A new accountant with the right rule
Job v2 with the fixed code
Reading the roll from receipt 1
Replaying the log from offset 0
Switching to the new sheet
Pointing users at view v2
Throwing away old receipts
Log retention deleting history
Fixing a bug without a batch system
🐞Find bugin v1 logic
→↓
πŸ”§Fix codedeploy as v2
→↓
πŸ”Replay logfrom the start
→↓
πŸ”€Switchwhen v2 caught up
→↓
πŸ—‘οΈRemove v1

04Why Do We Need It?

1️⃣One code base
The same job handles live data and old data, so there is nothing to keep in line.
🧩Simpler system
One processing system and one log, instead of batch, stream and merge.
πŸ”Easy reprocessing
New idea or bug fix? Replay the log into a new view.
πŸ§ͺSafe changes
v2 builds next to v1. Compare them before users switch.
⏱️Fresh results
Results are updated as events arrive, with no waiting for a batch run.
🧾Auditable history
The log shows exactly what happened and in what order.
If you can replay the log, you do not need a second system to recompute the past.

05Where Do We Use It?

πŸ“ŠReal-time analytics
Counts and dashboards built from an event log, with reprocessing when metrics change.
πŸ”Search and cache views
Build an index or cache from a log, and rebuild it when the schema changes.
πŸ”„Data sync
Keep several stores (search, cache, warehouse) updated from one stream of changes.
πŸ•΅οΈFraud and monitoring
Rules run on live events, and improved rules can be replayed on past events.
πŸ“‘IoT and telemetry
Sensor streams processed live and recomputed with better models.
🧱Event-sourced systems
State is already a function of an event log, so replay is natural.

06Types / Parts / How It Works

The parts of a Kappa system

PartWhat it doesExamples
LogStores ordered events for a long time and lets many readers replay from any offsetApache Kafka, Apache Pulsar, cloud streaming logs
Stream processorReads the log and computes views, keeping stateApache Flink, Kafka Streams, Spark Structured Streaming
Serving storeHolds the view so users can query it fastA database, search index or cache

Lambda and Kappa side by side

Two paths or one path
Lambda
πŸ“₯Events
βš™οΈBatch code
⚑Stream code
πŸ”€Merge
Kappa
πŸ“₯Events
πŸͺ΅Log (with history)
⚑Stream code (v1, v2)
Batch Stream Single path
Kappa removes the batch layer. The price is that the log must keep history and the stream engine must be trusted.

Ways to get history back

ApproachHow it worksGood and bad
Long retentionKeep every event in the log for a long timeSimple. Storage grows, and it can be costly.
Tiered storageMove old log segments to cheap object storage but still read them as part of the logCheap history. Replay of old data can be slower.
Compacted logKeep only the latest event for each keySmall. You lose the full history of changes.
Snapshot plus logSave a view snapshot now and then, and replay only the events after itFast restart. You must manage snapshots.
VisualizerFix a bug by replaying the logv1 adds refunds by mistake. Press Replay to rebuild the totals in v2 with the fixed code. Then shorten the log's retention and replay again to see what you cannot recover.
Users read totals from
The log, oldest on the left. B = purchase, R = refund. Dark = deleted by retention, green = read by v2, outlined = not read yet.
1B
2B
3B
4B
5R
6B
7R
8B
9B
10B
11B
12R
13B
14B
15B
16R
17B
18B
19B
20R
21B
22B
23B
24B
Userv1 (live)v2 Correct
Ann1800120
Ben145095
Cy1800150
Replayed
0 / 24
events v2 has read
Deleted
0
events the log forgot
Users with wrong totals
3
reading v1
v1 has a bug: it adds refunds instead of subtracting them. 3 of 3 users see a wrong total. Fix the code, deploy it as v2, and let it read the log from the start.

A tiny example: the log has 24 events and the replay reads one event per tick. A real replay reads millions of events per second, but the idea is the same.

07How to Use It / Steps / Implementation

Running a Kappa-style system

  1. 1
    Choose a log with history
    Pick a log you can read from any offset, and decide how long it keeps data. Make sure that is long enough to rebuild what you need.
  2. 2
    Write the job as a pure function of the log
    Same events in the same order should give the same result. Avoid reading the current time or random numbers inside the logic.
  3. 3
    Keep state safe
    Use the engine's state store and checkpoints, so the job can restart without losing its place.
  4. 4
    Design for replay speed
    A replay must run much faster than real time. Plan for more parallel workers during a replay.
  5. 5
    Deploy v2 next to v1
    Write v2 output to a new table or index. Do not overwrite v1 while v2 is catching up.
  6. 6
    Compare, then switch
    When v2 reaches the end of the log, compare it with v1 on sample data. Then move users to v2 and remove v1.
  7. 7
    Make output idempotent
    A replay or retry may write the same result twice. Use keys or upserts so repeats do no harm.
πŸ’‘Snapshots save time
If replaying a year of events takes too long, save a snapshot of the state now and then. A new job starts from the snapshot and replays only the events after it.
⚠️Retention is a decision
If the log deletes old events, you cannot replay them. Decide on retention based on what you must be able to recompute, not just on disk cost.

08Key Terms to Know

TermMeaning in easy words
LogAn ordered, append-only record of events that readers can replay
OffsetThe position of an event in the log. A consumer remembers its own offset
ReplayReading the log again from an earlier offset to rebuild a view
RetentionHow long the log keeps events before deleting them
ViewA table, index or cache that a job builds from the log
ReprocessingRecomputing results by running new logic over old events
DeterministicThe same input always gives the same output
CheckpointA saved copy of a job's state and position, for safe restarts
SnapshotA saved copy of a view at some point, to avoid replaying everything
Log compactionKeeping only the newest event for each key
CutoverSwitching users from the old view to the new one

09Pros, Cons and Trade-offs

βœ… Pros
  • One code base and one processing path
  • Fewer systems to run than Lambda
  • Fresh results as events arrive
  • Fix bugs and add features by replaying
  • Old and new versions can run side by side
⚠️ Cons
  • Needs a log that keeps enough history
  • Replaying a huge log can take a long time
  • Needs a stream engine that gives exact results
  • Not all work fits a stream, such as some heavy model training
  • Temporary double cost during a replay

Trade-offs

ChoiceWe gainWe lose
Long log retentionFull replay of historyMore storage and cost
Short log retentionCheap, small logCannot recompute old data without another copy
Replay from the startSimple and always correctSlow for very large logs
Snapshot plus replayFast catch-upExtra snapshot work and storage
Deploy v2 next to v1A safe switch with a way backTwo copies of the view for a while
Kappa instead of LambdaOne code baseDepends on the log and the stream engine doing everything

10Common Problems and Mistakes

Common mistakes

  1. Too little retention. The log forgot the early events, so a replay gives wrong totals.
  2. Non-deterministic logic. Using the current time or random values means a replay gives different answers from the live run.
  3. Switching too early. Users move to v2 before it has caught up and see partial results.
  4. Overwriting v1. v2 writes into the same table as v1 and breaks live traffic during the replay.
  5. Ignoring event order. Events from many partitions can arrive in a different order on replay, if the logic depends on global order.
  6. Non-idempotent output. A retry or replay creates duplicates in the destination.

Things to watch

⏳Replay time
Test how long a full replay takes. Add workers and snapshots if it is too slow.
πŸ’ΎLog storage cost
Long retention is costly. Tiered storage can cut it down.
🧬Schema changes
Old events may have an older format. Keep a schema history so replays can read them.
πŸ”’Deleting personal data
A log that keeps everything conflicts with deletion rules. Plan for it, for example with encryption keys you can delete.

11Real-World Examples

πŸͺ΅Log-centred design
The idea of one log as the base of the whole data system has been described by engineers working on Apache Kafka.
πŸ“ŠStreaming analytics
Companies run one Flink or Kafka Streams job for metrics and reprocess it when definitions change.
πŸ”ŽRebuilding search indexes
A new index is built from a log, then swapped in without downtime.
🏦Event-sourced finance apps
Balances are computed from a log of transactions, and can be recomputed.
πŸ“‘Telemetry pipelines
A better detection rule is replayed on stored sensor data.
🧊Tiered log storage
Several streaming platforms can move old log data to cheap object storage but still replay from it.
πŸ“Note
Kappa is an idea, not a product. Real systems often use a mix, such as a log plus occasional batch jobs for very heavy work.
Mini case: new revenue rule
πŸͺ΅Order log2 years kept
→↓live
πŸ“ŠRevenue v1old rule
⇒⇣replay
πŸ“ŠRevenue v2new rule
→↓switch
πŸ‘₯Finance team
Finance changes how refunds count. The team replays the log with v2 and switches when it catches up.

12Related Topics to Read Next

Lambda Architecture→

The two-path design that Kappa simplifies.

Streaming Engines→

The engines that run the one path.

Event Sourcing→

State built from a log of events, the same replay idea.

Message Brokers→

Kafka and similar tools that keep the log.

Batch vs Stream Processing→

The two styles of processing that these designs compare.

Change Data Capture (CDC)β†’

A way to fill the log with database changes.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”What: one stream path over a durable log. No separate batch layer.
  • βœ”Recompute: deploy v2, replay the log from offset 0, switch when it catches up.
  • βœ”Log needs: order, durability and enough retention (or tiered storage).
  • βœ”Job needs: deterministic logic, saved state and idempotent output.
  • βœ”Speed up replay: more workers and snapshots.
  • βœ”vs Lambda: one code base instead of two, but depends fully on the log and stream engine.
  • βœ”Watch: retention, replay time, schema changes, deleting personal data.
  • βœ”One line: β€œTo change the past, replay the log through new code.”
← Previous
Lambda Architecture
Next β†’
Streaming Engines