Log compaction is a Kafka feature that retains only the latest value for each key in a topic, removing older duplicates to save storage and ensure data freshness.
Click to reveal answer
beginner
How does Kafka decide which messages to keep during log compaction?
Kafka keeps the latest message for each unique key and removes older messages with the same key during log compaction.
Click to reveal answer
intermediate
What is the difference between log compaction and log retention by time?
Log retention by time deletes messages older than a set time, while log compaction keeps the latest message per key regardless of age.
Click to reveal answer
intermediate
Why is log compaction useful in Kafka?
It helps keep topics small by removing outdated data, supports stateful stream processing, and ensures consumers can recover the latest state efficiently.
Click to reveal answer
advanced
What happens if a message with a key is sent with a null value in a compacted topic?
A message with a null value acts as a delete marker (tombstone) for that key, so the key and its data are removed during compaction.
Click to reveal answer
What does Kafka's log compaction keep for each key?
AThe latest message only
BAll messages regardless of key
COnly messages older than a set time
DMessages with null values only
✗ Incorrect
Log compaction keeps only the latest message for each unique key.
What is the purpose of a tombstone message in a compacted topic?
ATo add a new key
BTo mark a key for deletion
CTo duplicate a message
DTo reset the topic
✗ Incorrect
A tombstone message has a null value and marks the key for deletion during compaction.
Which scenario best fits using log compaction?
AArchiving logs to cold storage
BStoring all sensor readings forever
CDeleting messages after 7 days
DKeeping the latest user profile updates
✗ Incorrect
Log compaction is ideal for keeping the latest state like user profiles.