What is the main purpose of interactive queries in Kafka Streams?
Interactive queries allow you to directly query the state stores of a Kafka Streams application to get real-time data without needing to go through Kafka topics.
Click to reveal answer
intermediate
How do you access a local state store in Kafka Streams for interactive queries?
You use the KafkaStreams#store() method with the store name and queryable store type to get a handle to the local state store.
Click to reveal answer
beginner
What is a key benefit of using interactive queries instead of querying Kafka topics directly?
Interactive queries provide low-latency, real-time access to aggregated or processed data stored locally, avoiding the overhead of consuming and processing raw Kafka topic data again.
Click to reveal answer
intermediate
What happens if the requested key is not found in the local state store during an interactive query?
If the key is not found locally, you can use Kafka Streams metadata APIs to find which instance has the key and then query that instance remotely.
Click to reveal answer
beginner
Name two types of state stores that can be queried interactively in Kafka Streams.
KeyValueStore and WindowStore are two common types of state stores that support interactive queries.
Click to reveal answer
What method is used to access a local state store for interactive queries in Kafka Streams?
AKafkaStreams#store()
BKafkaConsumer#poll()
CKafkaProducer#send()
DKafkaStreams#start()
✗ Incorrect
KafkaStreams#store() is the method to access local state stores for interactive queries.
Which of the following is NOT a benefit of interactive queries?
AReal-time access to processed data
BLow latency querying
CDirectly modifying Kafka topic data
DAvoiding reprocessing raw data
✗ Incorrect
Interactive queries do not allow direct modification of Kafka topic data; they provide read access to local state stores.
If a key is not found in the local state store, what can Kafka Streams do?
AQuery the Kafka topic directly
BUse metadata to find the instance that has the key and query it
CReturn null immediately
DRestart the Kafka Streams application
✗ Incorrect
Kafka Streams can use metadata APIs to locate the instance holding the key and query it remotely.
Which store type supports windowed data in interactive queries?
AWindowStore
BGlobalStore
CSessionStore
DKeyValueStore
✗ Incorrect
WindowStore supports windowed data and can be queried interactively.
Interactive queries are primarily used in which Kafka component?
AKafka Connect
BKafka Producer
CKafka Consumer
DKafka Streams
✗ Incorrect
Interactive queries are a feature of Kafka Streams to query local state stores.
Explain what interactive queries are in Kafka Streams and why they are useful.
Think about how you get data directly from your app's memory instead of reading from Kafka topics.
You got /4 concepts.
Describe the process Kafka Streams uses when a requested key is not found locally during an interactive query.
Consider how the app finds the right place to get the data if it’s not on the current machine.
You got /4 concepts.
Practice
(1/5)
1.
What is the main purpose of interactive queries in Kafka Streams?
easy
A. To create new Kafka topics dynamically
B. To write data back to Kafka topics
C. To read live state data directly from the Kafka Streams application
D. To monitor Kafka broker health status
Solution
Step 1: Understand interactive queries concept
Interactive queries allow reading live state from Kafka Streams state stores.
Step 2: Identify the main use case
The main use is to get real-time data from the app without extra databases.
Final Answer:
To read live state data directly from the Kafka Streams application -> Option C
Quick Check:
Interactive queries = read live state [OK]
Hint: Interactive queries read live state, not write or monitor [OK]
Common Mistakes:
Confusing interactive queries with writing data
Thinking it creates topics
Assuming it monitors brokers
2.
Which of the following is the correct way to get a state store named myStore of type ReadOnlyKeyValueStore in Kafka Streams?
easy
A. store = streams.store("myStore", ReadOnlyKeyValueStore.class);
B. store = streams.getStore("myStore", ReadOnlyKeyValueStore);
C. store = streams.getStore("myStore", ReadOnlyKeyValueStore.class);
D. store = streams.store("myStore", ReadOnlyKeyValueStore);
Solution
Step 1: Recall Kafka Streams store retrieval syntax
The correct method is streams.store(storeName, storeType.class) in Java.
Step 2: Match the correct syntax
store = streams.store("myStore", ReadOnlyKeyValueStore.class); uses streams.store with class type, which is correct method name and syntax.
Final Answer:
store = streams.store("myStore", ReadOnlyKeyValueStore.class); -> Option A
Quick Check:
Use streams.store with class type [OK]
Hint: Use streams.store("name", StoreClass.class) syntax [OK]
Common Mistakes:
Using streams.getStore instead of streams.store
Omitting .class for type
Passing type without .class
3.
Given the following code snippet in a Kafka Streams app, what will be the output if the key "user123" exists with value "active" in the state store?
var store = streams.store("userStatusStore", ReadOnlyKeyValueStore.class);
var status = store.get("user123");
System.out.println(status);
medium
A. null
B. "active"
C. Throws NullPointerException
D. Compilation error
Solution
Step 1: Understand store.get(key) behavior
The get method returns the value for the key if it exists, else null.
Step 2: Check given key and value
Since "user123" exists with value "active", store.get("user123") returns "active".
Final Answer:
"active" -> Option B
Quick Check:
store.get(existingKey) = value [OK]
Hint: store.get(key) returns value or null if missing [OK]
Common Mistakes:
Assuming null is returned even if key exists
Expecting exceptions on missing keys
Confusing syntax causing compile errors
4.
Identify the error in this Kafka Streams interactive query code snippet:
var store = streams.store("ordersStore", ReadOnlyKeyValueStore.class);
var order = store.get(12345);
System.out.println(order);
medium
A. Passing integer key instead of string key
B. Missing try-catch block for exceptions
C. Using streams.store instead of streams.getStore
D. Incorrect store type ReadOnlyKeyValueStore
Solution
Step 1: Check method to get state store
The method streams.store is correct.
Step 2: Validate key type and store type
Key type mismatch: passing integer 12345 instead of string key (common for ordersStore).
Final Answer:
Passing integer key instead of string key -> Option A
Quick Check:
Key type must match store definition [OK]
Hint: Use correct key type in store.get(key) [OK]
Common Mistakes:
Passing int literal without quotes for string keys
Assuming key type must be string always
Ignoring exception handling (not mandatory here)
5.
You want to build a real-time dashboard that shows the current count of active users using Kafka Streams interactive queries. Which approach best fits this requirement?
hard
A. Write user statuses to a separate database and query it periodically
B. Store counts in a local variable updated by Kafka Streams processors
C. Use Kafka consumer to read all user status events and aggregate externally
D. Use a ReadOnlyKeyValueStore to store user statuses and query counts live
Solution
Step 1: Identify real-time state storage method
Kafka Streams state stores hold live data accessible via interactive queries.
Step 2: Choose best approach for live dashboard
Using ReadOnlyKeyValueStore allows querying current counts directly without extra DB.
Final Answer:
Use a ReadOnlyKeyValueStore to store user statuses and query counts live -> Option D
Quick Check:
Interactive queries + state store = real-time dashboard [OK]
Hint: Use state store with interactive queries for live data [OK]
Common Mistakes:
Relying on external DB instead of state store
Polling Kafka consumer instead of querying store
Using local variables which are not shared state
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.