Challenge - 5 Problems
Kafka Streams Topology Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple Kafka Streams topology
What is the output printed by this Kafka Streams application when it processes the input record with key "key1" and value "hello"?
Kafka
StreamsBuilder builder = new StreamsBuilder(); KStream<String, String> source = builder.stream("input-topic"); KStream<String, String> uppercased = source.mapValues(value -> value.toUpperCase()); uppercased.to("output-topic"); // Assume the input record is ("key1", "hello") // The application prints the output record key and value after processing.
Attempts:
2 left
💡 Hint
Remember that mapValues changes only the value, not the key.
✗ Incorrect
The mapValues function transforms the value to uppercase but keeps the key unchanged. So the output record has the same key "key1" and the value "HELLO".
🧠 Conceptual
intermediate1:30remaining
Understanding Kafka Streams topology nodes
In a Kafka Streams topology, which node type is responsible for consuming records from Kafka topics?
Attempts:
2 left
💡 Hint
Think about where the data enters the topology.
✗ Incorrect
Source nodes read data from Kafka topics and feed it into the topology for processing.
❓ Predict Output
advanced2:30remaining
Output of a Kafka Streams topology with branching
Given this Kafka Streams topology code, what output records are sent to the "even-topic" and "odd-topic" when the input records have values 2 and 3?
Kafka
StreamsBuilder builder = new StreamsBuilder(); KStream<String, Integer> source = builder.stream("numbers-topic", Consumed.with(Serdes.String(), Serdes.Integer())); Map<String, KStream<String, Integer>> branches = source.split(Named.as("branch-")) .branch((key, value) -> value % 2 == 0, Branched.withConsumer(ks -> ks.to("even-topic"))) .branch((key, value) -> value % 2 != 0, Branched.withConsumer(ks -> ks.to("odd-topic"))) .noDefaultBranch();
Attempts:
2 left
💡 Hint
Check the condition for each branch carefully.
✗ Incorrect
The first branch filters even numbers and sends them to "even-topic"; the second branch filters odd numbers and sends them to "odd-topic".
🔧 Debug
advanced2:00remaining
Identify the error in Kafka Streams topology definition
What error will this Kafka Streams topology code produce when building the topology?
Kafka
StreamsBuilder builder = new StreamsBuilder(); KStream<String, String> source = builder.stream("input-topic"); source.filter((key, value) -> value.length() > 3); source.to("output-topic");
Attempts:
2 left
💡 Hint
Consider what happens to the filtered stream.
✗ Incorrect
The filter operation returns a new stream, but the original stream is sent to the output topic. So all records are sent, ignoring the filter.
❓ Predict Output
expert3:00remaining
Final output of a Kafka Streams topology with stateful aggregation
What is the output printed by this Kafka Streams topology after processing the input records ("key1", "apple"), ("key1", "banana"), and ("key1", "apple") on the "fruits-topic"?
Kafka
StreamsBuilder builder = new StreamsBuilder(); KStream<String, String> source = builder.stream("fruits-topic"); KTable<String, Long> counts = source.groupByKey().count(); counts.toStream().foreach((key, count) -> System.out.println(key + ": " + count));
Attempts:
2 left
💡 Hint
Count counts the number of records per key, regardless of value.
✗ Incorrect
The count aggregates the number of records with the same key. Three records with key "key1" are processed, so the count is 3.