Bird
Raised Fist0
Kafkadevops~20 mins

Join operations (KStream-KStream, KStream-KTable) in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kafka Streams Join Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of a KStream-KStream join with windowing
Given two KStreams joined with a 5-second tumbling window, what is the output when the following records arrive?

Stream1: (key=1, value=A) at t=1000ms
Stream2: (key=1, value=1) at t=4000ms
Stream2: (key=1, value=2) at t=7000ms

Assume the join concatenates values as value1+value2.
Kafka
KStream<String, String> stream1 = builder.stream("stream1");
KStream<String, String> stream2 = builder.stream("stream2");

KStream<String, String> joined = stream1.join(
    stream2,
    (v1, v2) -> v1 + v2,
    JoinWindows.ofTimeDifferenceWithNoGrace(Duration.ofSeconds(5))
);

joined.to("joined-output");
AOutput records: (1, A1) at ~1000ms only
BOutput records: (1, A1) at ~4000ms and (1, A2) at ~7000ms
COutput records: (1, A1) at ~4000ms only
DNo output records because window is too small
Attempts:
2 left
💡 Hint
Remember the join window allows matching records within 5 seconds of each other.
❓ Predict Output
intermediate
2:00remaining
Result of KStream-KTable join with missing key
What is the output when joining a KStream with a KTable if the KTable does not have the key present in the KStream record?

Stream record: (key=42, value=foo)
KTable contains keys: 1, 2, 3 only

Join function concatenates stream and table values with a dash.
Kafka
KStream<Integer, String> stream = builder.stream("stream-topic");
KTable<Integer, String> table = builder.table("table-topic");

KStream<Integer, String> joined = stream.leftJoin(
    table,
    (streamVal, tableVal) -> streamVal + "-" + (tableVal == null ? "null" : tableVal)
);

joined.to("joined-output");
ARuntime error due to missing key in KTable
BOutput record: (42, foo-null)
COutput record: (42, foo-)
DNo output record for key 42
Attempts:
2 left
💡 Hint
Left join emits stream records even if table key is missing, with null for table value.
🔧 Debug
advanced
2:00remaining
Identify the error in KStream-KStream join code
What error will this Kafka Streams code produce?

Code snippet:
```java KStream stream1 = builder.stream("s1"); KStream stream2 = builder.stream("s2"); KStream joined = stream1.join( stream2, (v1, v2) -> v1 + v2, JoinWindows.of(Duration.ofSeconds(10)) ); joined.to("out"); ```
Kafka
Same as prompt
ARuntime error: Missing Serdes configuration for join
BCompilation error: join requires a ValueJoiner with three parameters
CNo error, code runs and joins streams correctly
DCompilation error: JoinWindows.of(Duration) is deprecated, use ofTimeDifferenceWithNoGrace instead
Attempts:
2 left
💡 Hint
Check the Kafka Streams API for JoinWindows methods in recent versions.
📝 Syntax
advanced
2:00remaining
Syntax error in KStream-KTable join code
Which option contains the syntax error in this KStream-KTable join snippet?
Kafka
KStream<String, String> stream = builder.stream("stream");
KTable<String, String> table = builder.table("table");

KStream<String, String> joined = stream.join(
    table,
    (streamVal, tableVal) -> streamVal + tableVal
);

joined.to("output");
AMissing join type: should be leftJoin or innerJoin instead of join
BLambda parameters should be reversed: (tableVal, streamVal)
CMissing semicolon after joined.to("output")
DNo syntax error, code is correct
Attempts:
2 left
💡 Hint
Check Kafka Streams API for KStream-KTable join method names.
🚀 Application
expert
3:00remaining
Determine the number of output records from a complex join scenario
You have a KStream of orders and a KTable of customers. The KStream has 3 records with keys: 10, 20, 30. The KTable has customer data for keys: 10 and 30 only.

You perform a left join of the KStream with the KTable.

How many records will be emitted to the output topic?
Kafka
KStream<Integer, String> orders = builder.stream("orders");
KTable<Integer, String> customers = builder.table("customers");

KStream<Integer, String> joined = orders.leftJoin(
    customers,
    (orderVal, customerVal) -> orderVal + ":" + (customerVal == null ? "unknown" : customerVal)
);

joined.to("orders-with-customers");
A3 records
B2 records
C1 record
D0 records
Attempts:
2 left
💡 Hint
Left join emits all stream records regardless of table key presence.

Practice

(1/5)
1. What is the main difference between a KStream-KStream join and a KStream-KTable join in Kafka Streams?
easy
A. KStream-KStream joins require a time window; KStream-KTable joins do not.
B. KStream-KTable joins require a time window; KStream-KStream joins do not.
C. Both joins require a time window to match records.
D. Neither join requires a time window.

Solution

  1. Step 1: Understand KStream-KStream join behavior

    KStream-KStream joins combine records from two streams that occur within a specified time window.
  2. Step 2: Understand KStream-KTable join behavior

    KStream-KTable joins enrich stream records with the latest matching table record without needing a time window.
  3. Final Answer:

    KStream-KStream joins require a time window; KStream-KTable joins do not. -> Option A
  4. Quick Check:

    Time window needed only for KStream-KStream joins [OK]
Hint: Remember: only KStream-KStream joins need time windows [OK]
Common Mistakes:
  • Confusing which join requires a time window
  • Thinking both joins behave the same
  • Assuming KStream-KTable join needs time window
2. Which of the following is the correct syntax to perform a KStream-KTable join in Kafka Streams?
easy
A. ktable.join(kstream, (tableValue, streamValue) -> tableValue + streamValue);
B. kstream.join(ktable, JoinWindows.of(Duration.ofMinutes(5)), (v1, v2) -> v1 + v2);
C. kstream.join(ktable, (streamValue, tableValue) -> streamValue + tableValue);
D. kstream.join(ktable, (v1, v2) -> v1 + v2, JoinWindows.of(Duration.ofMinutes(5)));

Solution

  1. Step 1: Identify KStream-KTable join syntax

    KStream-KTable join uses kstream.join(ktable, ValueJoiner) without a time window.
  2. Step 2: Check options for correct method signature

    kstream.join(ktable, (streamValue, tableValue) -> streamValue + tableValue); matches the correct syntax: join without window and with a ValueJoiner lambda.
  3. Final Answer:

    kstream.join(ktable, (streamValue, tableValue) -> streamValue + tableValue); -> Option C
  4. Quick Check:

    KStream-KTable join syntax = kstream.join(ktable, (streamValue, tableValue) -> streamValue + tableValue); [OK]
Hint: KStream-KTable join has no time window parameter [OK]
Common Mistakes:
  • Adding JoinWindows to KStream-KTable join
  • Reversing stream and table parameters
  • Using KTable join method on KStream
3. Given the following Kafka Streams code snippet, what will be the output if the input streams have matching keys within the 5-minute window?
var joinedStream = stream1.join(stream2, (v1, v2) -> v1 + v2, JoinWindows.of(Duration.ofMinutes(5)));
joinedStream.foreach((key, value) -> System.out.println(key + ":" + value));
medium
A. Prints combined values for keys appearing in both streams within 5 minutes
B. Prints combined values for all keys in stream1 regardless of stream2
C. Prints only keys from stream2 with no combination
D. Throws a runtime exception due to missing KTable

Solution

  1. Step 1: Understand KStream-KStream join with window

    The join combines records from both streams with matching keys occurring within the 5-minute window.
  2. Step 2: Analyze output behavior

    For matching keys within the window, the values are combined using the lambda (v1 + v2) and printed.
  3. Final Answer:

    Prints combined values for keys appearing in both streams within 5 minutes -> Option A
  4. Quick Check:

    KStream-KStream join outputs combined matching keys [OK]
Hint: KStream-KStream join outputs combined values within window [OK]
Common Mistakes:
  • Assuming all keys from stream1 print regardless of stream2
  • Confusing KStream-KTable join behavior
  • Expecting runtime error without KTable
4. Identify the error in the following Kafka Streams join code:
var joined = stream1.join(stream2, (v1, v2) -> v1 + v2);
joined.print();
medium
A. Incorrect lambda syntax for join function
B. Missing JoinWindows parameter for KStream-KStream join
C. Using print() instead of foreach() causes error
D. stream2 should be a KTable, not a KStream

Solution

  1. Step 1: Check join method parameters

    KStream-KStream join requires a JoinWindows parameter to specify the time window for matching events.
  2. Step 2: Identify missing parameter

    The code omits the JoinWindows argument, causing a compilation error.
  3. Final Answer:

    Missing JoinWindows parameter for KStream-KStream join -> Option B
  4. Quick Check:

    KStream-KStream join needs JoinWindows [OK]
Hint: KStream-KStream join always needs JoinWindows [OK]
Common Mistakes:
  • Forgetting JoinWindows in KStream-KStream join
  • Confusing KStream-KTable join syntax
  • Assuming print() is invalid method
5. You want to enrich a stream of user clicks (KStream) with the latest user profile data stored in a KTable. Which join operation should you use and why?
hard
A. Use KStream-KStream join without a window to join clicks and profiles.
B. Use KStream-KStream join with a 10-minute window to combine clicks and profiles.
C. Use KTable-KTable join because both are tables.
D. Use KStream-KTable join to enrich clicks with latest profile data without time window.

Solution

  1. Step 1: Identify data types and join needs

    User clicks are a stream (KStream), and user profiles are stored as a table (KTable).
  2. Step 2: Choose appropriate join type

    KStream-KTable join enriches stream data with the latest table data for matching keys without needing a time window.
  3. Final Answer:

    Use KStream-KTable join to enrich clicks with latest profile data without time window. -> Option D
  4. Quick Check:

    KStream-KTable join enriches stream with latest table data [OK]
Hint: Enrich stream with table data using KStream-KTable join [OK]
Common Mistakes:
  • Using KStream-KStream join unnecessarily
  • Adding time window to KStream-KTable join
  • Confusing KTable-KTable join for stream enrichment
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard