Kafka prevents data loss through a combination of replication, disk persistence, and producer acknowledgment settings that together ensure a record isn't considered "written" until it's safely stored on enough replicas.
Key Points: • Every record is written to disk on the partition leader and replicated to follower brokers, so a single broker crash doesn't erase committed data. • Producers can require acknowledgment from all in-sync replicas (acks=all) before treating a send as successful, combined with min.insync.replicas to enforce a minimum safe replica count. • If a producer doesn't receive an acknowledgment, it can retry the send; idempotent producers (enable.idempotence=true) ensure retries don't create duplicate records. • Consumers track their progress via offsets, and committing offsets only after successful processing avoids marking data as consumed before it's safely handled.
Example: A producer configured with acks=all, min.insync.replicas=2, and enable.idempotence=true writing to a topic with replication factor 3 can survive a broker failure mid-write without losing the record or creating a duplicate, since the write is only acknowledged once it's durably replicated.
Interview Tip: A concise interview answer is:
"Kafka avoids data loss through replication and disk persistence on the broker side, and through acks=all with a proper min.insync.replicas on the producer side, so a write is only acknowledged once it's safely stored on multiple replicas, and idempotent producers make sure retries after a failure don't create duplicates."