8 The KTable API

 

This chapter covers

  • Changelog streams, the KTable, and the GlobalKTable
  • Aggregating records with a KTable
  • Enriching event streams with joins
  • Joining a KTable with another KTable

This chapter will introduce you to a new API in Kafka Streams, the Ktable. The KTable is an update or changelog stream. You’ve already used a KTable as any aggregation operations in Kafka Streams result in a KTable. The KTable is an essential abstraction for working with records with the same key. In a KStream, records with the same key are independent events. But in the KTable, a record updates the previous one with the same key.

Why is learning about an update stream necessary? Sometimes, you’ll only care about the latest entry for a given piece of data. For example, consider a user profile. When someone updates their profile, only the newest entry is correct. All previous versions of the profile don’t matter. Compared to a relational database, the event stream (a KStream) could be considered a series of inserts where the primary key is an auto-incrementing number. Each insert of a new record has no relationship to previous ones. But with a KTable, the key in the key-value pair is the primary key. So, instead of inserting a new row, an update to the row results.

8.1 KTable: The update stream

8.1.1 Updates to records or the changelog

8.1.2 KStream and KTable API in action

8.2 KTables are stateful

8.3 The KTable API

8.4 KTable aggregations

8.5 GlobalKTable

8.6 Table joins

8.6.1 Stream–table join details

8.6.2 Versioned KTables

8.6.3 Stream–global table join details

8.6.4 Table–table join details

Summary