Apache Kafka Kafka Streams 2 — Questions and Answers
Question 1: What is a 'tumbling window' in Kafka Streams?
- A fixed-size, non-overlapping time window where each record belongs to exactly one window (Correct answer)
- A sliding window that moves forward by a fixed step
- A session window defined by inactivity gaps
- An unbounded window that aggregates all records
Correct answer: A fixed-size, non-overlapping time window where each record belongs to exactly one window
Tumbling windows partition time into equal-sized, non-overlapping buckets so each event falls into exactly one window.
Question 2: What is the purpose of `StreamsConfig.APPLICATION_ID_CONFIG`?
- Uniquely identifies the Kafka Streams application and is used as the consumer group ID and internal topic prefix (Correct answer)
- Sets the Kafka broker address
- Configures the state store directory
- Defines the number of stream threads
Correct answer: Uniquely identifies the Kafka Streams application and is used as the consumer group ID and internal topic prefix
The application ID serves as the consumer group ID for all internal consumers and is prepended to internal changelog and repartition topic names.
Question 3: What does the `filter()` operation do in a Kafka Streams topology?
- Passes only records that satisfy a given predicate, dropping the rest (Correct answer)
- Transforms each record's value
- Splits the stream into multiple sub-streams
- Joins two streams on a common key
Correct answer: Passes only records that satisfy a given predicate, dropping the rest
filter() evaluates a Predicate for each record and only forwards records where the predicate returns true.
Question 4: What is a 'changelog topic' in Kafka Streams?
- A Kafka topic used to back up local state store contents for fault tolerance (Correct answer)
- A topic storing consumer group offset changes
- A topic tracking producer configuration changes
- An admin topic for broker metadata
Correct answer: A Kafka topic used to back up local state store contents for fault tolerance
Kafka Streams writes all state store updates to a changelog topic so that state can be restored from Kafka if a task migrates to another instance.
Question 5: What does `flatMapValues()` do in Kafka Streams?
- Transforms each record's value into zero or more values, emitting one record per resulting value (Correct answer)
- Joins two streams' values
- Flattens a nested topic hierarchy
- Converts a KTable to a KStream
Correct answer: Transforms each record's value into zero or more values, emitting one record per resulting value
flatMapValues() applies a function to each record's value that returns an iterable, emitting a separate downstream record for each element.
Question 6: What is a 'session window' in Kafka Streams?
- A dynamic window that groups records separated by an inactivity gap smaller than a configurable threshold (Correct answer)
- A fixed 30-minute window
- A window tied to the user's login session
- A window that resets every hour
Correct answer: A dynamic window that groups records separated by an inactivity gap smaller than a configurable threshold
Session windows group events for a key into a session as long as the gap between consecutive events is less than the inactivity gap timeout.
What is a 'tumbling window' in Kafka Streams?