liveBook · Manning

Stream-global-table join

As explained in Kafka Streams in Action, Second Edition

A stream-global-table join combines records from a KStream with matching records in a fully replicated GlobalKTable.

A stream–global table join enriches each KStream record with matching metadata from a fully replicated GlobalKTable. Unlike ordinary stream–table joins, it does not require co-partitioning, so the stream may use null keys or keys unrelated to the global table. section 8.6 section 8.6.3

Use the join when:

  • The stream records lack keys, but a field in each value identifies the matching global-table record. section 8.6.3
  • The stream key differs from the GlobalKTable key and must be translated before lookup. section 8.6.3
  • The application needs an enriched event containing information from both the incoming stream record and replicated reference data. section 8.6

The KStream–GlobalKTable API takes three main components: the stream, the GlobalKTable, and a KeyValueMapper. The mapper receives the stream key and value and returns the key used to query the global table. A ValueJoiner then combines the stream value with the matched table value. The resulting record retains the stream’s key, even when that key is null or differs from the lookup key. section 8.6.3

Enriching unkeyed sensor readings

A manufacturing application reads sensor measurements without Kafka keys and joins them with a GlobalKTable containing sensor metadata. The mapper extracts the sensor ID from the Sensor value, while the joiner combines the reading with location information: sensorKStream.join(sensorInfoGlobalKTable, sensorIdExtractor, sensorValueJoiner). Kafka Streams updates the GlobalKTable through a separate dedicated thread outside normal incoming-record processing. section 8.6.3

Listing 8.10 KstreamGlobalTable join example
sensorKStream.join(sensorInfoGlobalKTable,           #1
                       sensorIdExtractor,       #2
                       sensorValueJoiner);     #3

Inspect the compact three-argument KStream–GlobalKTable join shape before following the mapper and value-joiner details. section 8.6.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains replication, key extraction, result-key behavior, joiner roles, and GlobalKTable update processing through Java examples.
Examples
Demonstrates website clickstream enrichment and unkeyed manufacturing sensor readings joined with sensor metadata.
What it assumes
Assumes familiarity with KStream records and table-backed Kafka data while explaining co-partitioning and join-key translation.
What you can do after
Build a Kafka Streams enrichment pipeline using a key extractor and value joiner against a GlobalKTable.
How it connects
Connects KStream, GlobalKTable, KTable, co-partitioning, repartitioning, foreign-key joins, KeyValueMapper, and ValueJoiner.

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.