Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Kafka Log Compaction Deep Dive: Cleaner threads, dirty ratio, compaction tombstone records, and `min.compaction.lag.ms`.
senior LevelSystem DesignApache KafkaMicroservices
In Simple Words: For key-value topics (e.g. user account profiles), log compaction guarantees that Kafka retains at least the last known value for each record key indefinitely:
- Log Cleaner Threads: Background threads that scan log segments, building an in-memory hash map of the latest key offsets, and rewrite clean segments discarding superseded records.
- Tombstones (Deletions): A record with a valid key and a
nullvalue payload is a tombstone. Cleaner threads retain tombstones fordelete.retention.ms(default 24h) to allow all consumers to observe the deletion before permanent disk purge.