← Lessons

quiz vs the machine

Platinum1740

System Design

Stream Table Duality

How a stream of changes and a table of current state are two views of the same data.

6 min read · advanced · beat Platinum to climb

Two views of one truth

A stream is an unbounded sequence of immutable events. A table is a snapshot of the current value for each key. Stream table duality says these are two views of the same data and you can convert between them.

Stream to table

Replaying a stream of updates and keeping only the latest value per key builds a table. Each event is interpreted as an insert or update, so the table reflects the accumulated effect of the stream. This is exactly what a compacted topic gives you.

Table to stream

Watching a table for changes and emitting each change as an event yields a stream, the changelog of the table. Every insert, update, and delete becomes a record.

Why it matters

This duality lets processing engines join a stream against a table, materialize a stream into a queryable view, and rebuild a table by replaying its changelog. State and events become interchangeable.

Key idea

A stream aggregated by key becomes a table, and a table watched for changes becomes a stream, so events and state are interchangeable views of the same data.

Check yourself

Answer to earn rating on the learn ladder.

1. How do you turn a stream into a table?

2. What is a table viewed as a stream?

3. Which Kafka feature directly embodies stream to table conversion?