Kafka Streams: KStream & KTable

Streams = events; tables = state. The DSL lets you move between them.

0/3 done

Stream ↔ table duality

The two abstractions

  • KStream — an unbounded sequence of records; events.
  • KTable — a changelog-backed view of the latest value per key; state.

Move from stream → table by aggregation. Move from table → stream by toStream(). Both are backed by Kafka topics, so failover is just 'replay the changelog'.

We use a Python-friendly Faust-style snippet here for visual brevity — production Kafka Streams is JVM-native; the shape of the program is identical.

Word-count topology (Python / Faust-style)

Author the canonical word-count: read sentences, split on whitespace, group by word, count into a KTable. Note the table() call — that's the stream→table transition.

Reading in progress · 0 of 3 activities done