0
0
Kafkadevops~20 mins

Why stream processing transforms data in Kafka - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stream Processing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kafka Streams transformation?

Consider a Kafka Streams application that reads a stream of user clicks and transforms the data to count clicks per user.

streamsBuilder.stream("clicks")
  .map((key, value) -> KeyValue.pair(value.getUserId(), 1))
  .groupByKey()
  .count()
  .toStream()
  .foreach((userId, count) -> System.out.println(userId + ": " + count));

If the input stream has these records:

  • key=null, value={userId: "alice"}
  • key=null, value={userId: "bob"}
  • key=null, value={userId: "alice"}

What will be printed?

Kafka
streamsBuilder.stream("clicks")
  .map((key, value) -> KeyValue.pair(value.getUserId(), 1))
  .groupByKey()
  .count()
  .toStream()
  .foreach((userId, count) -> System.out.println(userId + ": " + count));
A
alice: 2
bob: 1
Bnull: 3
C
alice: 1
bob: 1
DNo output, because key is null
Attempts:
2 left
💡 Hint

Think about how the map step changes the key to the userId, enabling grouping by user.

🧠 Conceptual
intermediate
1:30remaining
Why do stream processing systems transform data?

Why is it important for stream processing systems like Kafka Streams to transform data as it flows through the pipeline?

ATo store all raw data permanently without changes
BTo convert data into images for visualization
CTo enrich, filter, or aggregate data in real-time for faster insights
DTo slow down the data flow for batch processing later
Attempts:
2 left
💡 Hint

Think about what real-time data processing aims to achieve.

🔧 Debug
advanced
2:00remaining
Identify the error in this Kafka Streams transformation code

Look at this Kafka Streams code snippet:

streamsBuilder.stream("orders")
  .filter((key, value) -> value.getAmount() > 100)
  .mapValues(value -> value.getCustomerName())
  .to("high-value-customers");

What error will this code cause when run?

ACompilation error due to missing semicolon
BLogical error: filter condition is reversed
CNo error, code runs correctly
DRuntime error because <code>to</code> requires a key serializer but key is null
Attempts:
2 left
💡 Hint

Consider what happens to the key after mapValues and what to expects.

📝 Syntax
advanced
1:30remaining
Which option correctly transforms a stream to uppercase values?

Given a Kafka Streams input stream of strings, which code snippet correctly transforms all values to uppercase?

AstreamsBuilder.stream("input").mapValues(value -> value.toUpperCase()).to("output");
BstreamsBuilder.stream("input").map((key, value) -> value.toUpperCase()).to("output");
CstreamsBuilder.stream("input").mapValues(value -> value.uppercase()).to("output");
DstreamsBuilder.stream("input").mapValues(value -> value.toUpper()).to("output");
Attempts:
2 left
💡 Hint

Remember the correct Java method name for uppercase conversion.

🚀 Application
expert
2:30remaining
How does stream processing enable real-time fraud detection?

Imagine a bank uses Kafka Streams to detect fraudulent transactions in real-time. Which transformation best supports this use case?

ABatch processing transactions once a day for fraud reports
BFiltering transactions above a threshold and aggregating counts per account within a time window
CStoring all transactions in a database without processing
DConverting transactions to JSON strings without filtering
Attempts:
2 left
💡 Hint

Think about how to spot suspicious activity quickly using streaming data.