liveBook · Manning

JoinWindows

As explained in Kafka Streams in Action, Second Edition

A join window is a time interval that determines which records from two streams are eligible to be joined based on their timestamps.

JoinWindows defines the timestamp interval in which records from two Kafka Streams are eligible to produce a stream-stream join result. With a 30-minute window, a 12:00 coffee purchase can join a store purchase timestamped from 11:30 through 12:30. section 7.3.4

Configure the window according to the timing relationship your application accepts:

  • Use JoinWindows.ofTimeDifferenceWithNoGrace(Duration.minutes(30)) for a symmetric maximum difference before or after the calling stream's timestamp. section 7.3.1 section 7.3.4
  • Use after(Duration.ofMinutes(5)) to keep a 30-minute opening side but limit the secondary record to five minutes after the primary timestamp. section 7.3.4
  • Use before(Duration.ofMinutes(5)) to limit the secondary record to five minutes before the primary timestamp while retaining the 30-minute closing side. section 7.3.4

Joining coffee and store purchases

A Kafka Streams application can create JoinWindows and pass it to KStream.join alongside a ValueJoiner and StreamJoined configuration: JoinWindows thirtyMinuteWindow = JoinWindows.ofTimeDifferenceWithNoGrace(Duration.minutes(30));. Kafka Streams stores records from both sides in windowed state stores, then looks up records with the same key whose timestamps fall within the configured interval. section 7.3.1 section 7.3.2

Figure 7.14 The JoinWindows configuration specifies the max difference (before or after) from the timestamp of the calling side the secondary side can have to create a join result.
figure

Use the timestamp diagram to see how the calling stream's timestamp anchors the allowed interval for the secondary stream. section 7.3.4

JoinWindows controls time matching, not partition alignment. Join participants must be co-partitioned with the same partition count and key type; record timestamps come from Kafka or a configured TimestampExtractor. section 7.3.5

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains symmetric and asymmetric intervals, then connects them to state-store lookups; defers timestamp extraction semantics.
Examples
Uses coffee and store purchase streams with 30-minute, shortened-after, and shortened-before timestamp ranges.
What you can do after
Configure Kafka Streams join timing with ofTimeDifferenceWithNoGrace, before, and after.
How it connects
Connects stream-stream joins with timestamps, state stores, ValueJoiner, Serdes, and co-partitioning.

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.