How does Kafka ensure data is not lost?

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

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.

# Producer (application.properties)
spring.kafka.producer.acks=all
spring.kafka.producer.properties.enable.idempotence=true
spring.kafka.producer.retries=2147483647

# Topic: 3 copies, at least 2 must confirm each write
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic payments \
  --partitions 6 --replication-factor 3 --config min.insync.replicas=2

// Consumer: commit the offset only after the record is safely stored
@KafkaListener(topics = "payments", groupId = "ledger")
public void onPayment(String payment, Acknowledgment ack) {
    ledgerRepository.save(parse(payment));
    ack.acknowledge();      // needs spring.kafka.listener.ack-mode=manual
}

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.

Last updated: 1 November 2026

Previous question: What is the role of replication in Kafka?

Next question: What is the significance of the acks (acknowledgement) setting for Kafka producers?

More Kafka (Optional) interview questions

All Kafka (Optional) questions