Apache Kafka Streaming (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the difference between Log Retention (Delete) and Log Compaction?
junior LevelApache Kafka
In Simple Words:
- Log Retention (
cleanup.policy=delete): Purges records based strictly on age or total partition size. - Log Compaction (
cleanup.policy=compact): Retains at least the most recent value for every key within a partition log.- Older records with the same key are deleted during background cleaning.
- If a producer writes
user_1 -> { status: "ACTIVE" }and later writesuser_1 -> { status: "SUSPENDED" }, compaction permanently deletes the older "ACTIVE" record. - Tombstone Record: Writing a key with a
nullpayload acts as a tombstone, instructing the compactor to permanently delete that key on the next compaction cycle. - Primary Use Cases: Rebuilding state stores (RocksDB in Kafka Streams), database changelogs, user profile caches.