© Anton Dolganin 2025
We have two streams: streamA
and streamB
. We need to join them by key, but not all events exist in both streams.
Join Types Comparison:
Join Type | Behavior |
---|---|
Inner | Only pairs where the key exists in both |
Left | All from streamA, plus streamB if present |
Outer | All pairs from both streams, even if one side is missing |
KStream<String, String> streamA = builder.stream("streamA");
KStream<String, String> streamB = builder.stream("streamB");
KStream<String, String> joined = streamA.leftJoin(
streamB,
(valueA, valueB) -> valueA + ":" + (valueB == null ? "NO_MATCH" : valueB),
JoinWindows.of(Duration.ofMinutes(5))
);
joined.to("joined-topic");
What happens:
If streamA
has a key but streamB
doesn’t, it returns valueA:NO_MATCH
.
If both have the key, it returns the combined value.
Outer Join
additionally includes records from streamB with no match in streamA.
Real-World Example — Correlating Orders and Payments in an E-commerce System:
orders
(key: order_id, value: order details)payments
(key: order_id, value: payment details)Inner Join
Left Join
Outer Join
© Anton Dolganin 2025