Bird
Raised Fist0

Find the bug in this Kafka Streams session window code:

medium📝 Debug Q7 of Q15
Kafka - Streams
Find the bug in this Kafka Streams session window code:
stream.groupByKey()
  .windowedBy(SessionWindows.with(Duration.ofSeconds(30)))
  .count()
AMissing .toStream() after count() causes error
BSessionWindows.with() is deprecated; use withInactivityGap() instead
CNo bug; code is correct
DSessionWindows.with() requires an inactivity gap, not window size
Step-by-Step Solution
Solution:
  1. Step 1: Understand SessionWindows.with() parameter

    SessionWindows.with(Duration.ofSeconds(30)) correctly sets the inactivity gap to 30 seconds for the session window.
  2. Step 2: Check code correctness

    The code groups by key, applies session windowing, and counts events, producing a valid windowed aggregation.
  3. Final Answer:

    No error; code is correct -> Option C
  4. Quick Check:

    SessionWindows.with() = valid inactivity gap configuration [OK]
Quick Trick: SessionWindows.with() sets inactivity gap, not fixed window size [OK]
Common Mistakes:
MISTAKES
  • Confusing inactivity gap with window size
  • Assuming SessionWindows.with() defines fixed windows
  • Ignoring need for toStream() after count()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes