Challenge - 5 Problems
Kafka Interactive Queries Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Kafka Streams interactive query?
Consider a Kafka Streams application with a state store named
Assuming the store contains the entry
user-store. The following code snippet queries the store for a user ID and prints the result.ReadOnlyKeyValueStore<String, String> store = streams.store(StoreQueryParameters.fromNameAndType("user-store", QueryableStoreTypes.keyValueStore()));
String user = store.get("user123");
System.out.println(user);Assuming the store contains the entry
{"user123": "Alice"}, what will be printed?Kafka
ReadOnlyKeyValueStore<String, String> store = streams.store(StoreQueryParameters.fromNameAndType("user-store", QueryableStoreTypes.keyValueStore())); String user = store.get("user123"); System.out.println(user);
Attempts:
2 left
💡 Hint
The store.get() method returns the value associated with the key or null if not found.
✗ Incorrect
The key "user123" exists in the store with value "Alice", so store.get("user123") returns "Alice" which is printed.
🧠 Conceptual
intermediate1:30remaining
Which statement about Kafka Streams interactive queries is true?
Select the correct statement about interactive queries in Kafka Streams.
Attempts:
2 left
💡 Hint
Think about where the state store lives and how queries access it.
✗ Incorrect
Interactive queries let you query the local state store directly without stopping the app or querying Kafka brokers.
🔧 Debug
advanced2:30remaining
Why does this interactive query code throw an exception?
Given the following code snippet:
When running, it throws a
ReadOnlyKeyValueStore<String, String> store = streams.store("user-store", QueryableStoreTypes.keyValueStore());
String user = store.get("user123");
System.out.println(user);When running, it throws a
IllegalArgumentException. What is the cause?Attempts:
2 left
💡 Hint
Check the method signature for streams.store() in recent Kafka versions.
✗ Incorrect
The streams.store() method requires a StoreQueryParameters object since Kafka 2.4. Passing name and type separately causes IllegalArgumentException.
📝 Syntax
advanced2:30remaining
Which code snippet correctly performs an interactive query to get all entries from a key-value store?
You want to iterate over all entries in a local key-value store named
user-store. Which snippet is correct?Attempts:
2 left
💡 Hint
Check the correct method to get all entries and how to iterate the KeyValueIterator.
✗ Incorrect
The store.all() method returns a KeyValueIterator which must be iterated with hasNext()/next() and closed after use. Option A follows this pattern correctly.
🚀 Application
expert3:00remaining
How to implement a fault-tolerant interactive query across multiple Kafka Streams instances?
You have a Kafka Streams application running on 3 instances, each with a local state store
user-store. You want to query the state for a user ID, but the key may be on any instance. Which approach ensures fault-tolerant interactive queries?Attempts:
2 left
💡 Hint
Think about how Kafka Streams partitions state and how to locate the correct instance.
✗ Incorrect
Kafka Streams partitions state stores by key. The Metadata API tells which instance hosts a key. Querying that instance via REST is fault-tolerant and efficient.