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.
Shows repeated keyed records overwriting earlier values, making the difference between an event stream and an update stream visible. section 8.1.1
