What mechanisms does Kafka use to ensure message durability?
Instruction: Discuss the features and mechanisms Kafka employs to ensure that messages are not lost and can be recovered in case of system failures.
Updated
Official answer
Kafka durability depends on replication, acknowledgement policy and the failures being considered. Replication factor alone is not a complete guarantee.
A common starting configuration is replication factor 3, producer acks=all, and topic min.insync.replicas=2, with replicas spread across independent failure domains. acks=all waits for the current in-sync replica set; the minimum setting prevents successful writes when too few replicas remain in sync. With only one in-sync replica, this configuration sacrifices write availability rather than accepting a weakly replicated write. It does not promise continued writes through any two broker failures.
Avoid unclean leader election when electing an out-of-sync replica would violate the data-loss policy. Plan for disk failure, correlated outages and operator mistakes as well as a single process crash. Normal acknowledgement uses Kafka's replication design; it is not a promise that each record was individually fsynced to every disk before acknowledgement.
Handle producer errors and uncertain outcomes. Idempotent production addresses duplicates from supported producer retries, while transactions can group Kafka writes and consumed offsets. Neither automatically deduplicates a new business request or atomically updates an unrelated external system.
Retention controls how long replay data remains available. Time/size deletion and compaction can intentionally remove records; size recovery headroom for expected outages. A compacted current-state topic is not a complete historical backup.
Consumer offset commits track progress, not broker-record durability. The committed position is the next record to read, and committing before processing completes can skip work after a crash. Processing before committing can replay work, so use idempotent effects or an appropriate transaction strategy.
Sources
Kafka producer acknowledgements and idempotence; topic minimum ISR and retention; Kafka replication and delivery design.
Related Questions
-
easy
-
easy
-
easy
-
medium
-
medium
-
hard