0
0
Kafkadevops~20 mins

KStream and KTable concepts in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Streams 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 KStream aggregation?
Consider a KStream that reads user clicks and counts clicks per user. What will be the output after aggregation?
Kafka
KStream<String, String> clicks = builder.stream("clicks-topic");
KTable<String, Long> clickCounts = clicks.groupByKey().count();
clickCounts.toStream().foreach((user, count) -> System.out.println(user + ": " + count));
AThrows a runtime error because count() is not valid on KStream
BPrints only the first click per user and stops updating
CPrints all clicks without aggregation
DPrints each user with their total click count, updating as new clicks arrive
Attempts:
2 left
💡 Hint
Think about how KTable represents aggregated state and updates.
🧠 Conceptual
intermediate
1:30remaining
Difference between KStream and KTable
Which statement correctly describes the difference between KStream and KTable?
AKStream represents a stream of immutable events; KTable represents a changelog stream of updates to a table
BKStream stores the latest value per key; KTable stores all events without aggregation
CKStream is used only for input; KTable is used only for output
DKStream and KTable are identical and interchangeable
Attempts:
2 left
💡 Hint
Think about how data changes over time in each abstraction.
🔧 Debug
advanced
2:30remaining
Why does this KTable join produce no output?
Given two KTables joined on key, why does the join produce no output?
Kafka
KTable<String, String> table1 = builder.table("topic1");
KTable<String, String> table2 = builder.table("topic2");
KTable<String, String> joined = table1.join(table2, (v1, v2) -> v1 + v2);
joined.toStream().foreach((k,v) -> System.out.println(k + ": " + v));
ABecause the topics "topic1" and "topic2" have no overlapping keys
BBecause the join function returns null
CBecause join() is not supported on KTables
DBecause toStream() does not convert KTable to a stream
Attempts:
2 left
💡 Hint
Think about what keys must exist in both tables for a join to produce output.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this KStream filter code
Which option contains the correct syntax to filter a KStream for values starting with "error"?
Kafka
KStream<String, String> logs = builder.stream("logs-topic");
KStream<String, String> errors = logs.filter((key, value) -> value.startsWith("error"));
Alogs.filter((k, v) -> { return value.startsWith("error"); });
Blogs.filter(key, value -> value.startsWith("error"));
Clogs.filter((key, value) -> value.startsWith("error"));
Dlogs.filter((key, value) => value.startsWith("error"));
Attempts:
2 left
💡 Hint
Check the lambda syntax and parameter usage in Java.
🚀 Application
expert
2:30remaining
How many items are in the resulting KTable after this aggregation?
Given a KStream of orders keyed by orderId, this code groups by customerId and counts orders per customer. How many entries will the resulting KTable have if there are 1000 orders from 100 distinct customers?
Kafka
KStream<String, Order> orders = builder.stream("orders-topic");
KTable<String, Long> ordersPerCustomer = orders.groupBy((orderId, order) -> order.getCustomerId()).count();
A1000
B100
C0
DDepends on the order of processing
Attempts:
2 left
💡 Hint
Think about grouping by customerId and counting orders per customer.