liveBook · Manning

Update stream

As explained in Kafka Streams in Action, Second Edition

An update stream is a continuous flow of records in which a record sharing a key with an earlier record represents an update to that record.

An update stream is a continuous flow of records where a repeated key identifies a change to the earlier record. It models the latest value for each key rather than treating every record as an independent event. section 8.0 section 8.1.1

Use this mental model to distinguish update streams from event streams:

  • Treat each key as a primary key in a table; a later record with that key updates the earlier value. section 8.0
  • Contrast an event stream, where records with the same key remain independent events, with an update stream, where they form a record history. section 8.1 section 8.1.1
  • Represent the stream as a changelog: records are appended, but older values for a key can be removed through log compaction. section 8.1.1
  • Use a null value as a tombstone when the keyed record must be deleted. section 8.2

Customer purchases as updates

Key customer transactions by customer ID to relate purchases over time. Repeated transactions for one customer then update that customer’s accumulated table entry instead of remaining unrelated events. section 8.1.1

Stock ticker with KStream and KTable

A stock ticker publishes nine quotes in three iterations. The KStream prints all nine because it processes individual events; the KTable prints three latest records because repeated keys are updates. Convert the KTable with toStream() before printing. section 8.1.2

Figure 8.4 In a changelog, each incoming record overwrites the previous one with the same key. You’d have four events with a record stream, but for an update stream, you have only two.
figure

Shows repeated keyed records overwriting earlier values, making the difference between an event stream and an update stream visible. section 8.1.1

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains keys, changelogs, compaction, tombstones, and KStream/KTable behavior, while deferring detailed update-emission mechanisms.
Examples
Uses stock quotes, customer purchases, database-table inserts, changelog overwrites, and Java console-printing examples.
What it assumes
Assumes familiarity with event streams and KStream, while establishing the stream-to-table relationship and keyed updates.
What you can do after
Apply it via Kafka Streams by choosing KStream or KTable semantics, converting between them, and handling keyed deletion with tombstones.
How it connects
Connects update streams with KTable, KStream, changelog, log compaction, state stores, aggregations, and joins.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.