How does Kafka ensure data is replicated across the cluster?
Instruction: Explain the process through which Kafka achieves data replication.
Updated
Official answer
Replication is configured per partition through its assigned replica set. A topic commonly uses a uniform replication factor: a factor of three means three assigned replicas of each partition, not that all three are currently healthy and caught up.
The leader appends records and followers fetch the log. Kafka tracks replica progress and the in-sync replica set. The high watermark marks a committed replication boundary; it is not evidence that each replica forced every record to durable media with fsync.
Producer acknowledgement settings determine when a send is reported successful. With acks=1 the leader can respond before followers have replicated the record. With acks=all, the applicable in-sync acknowledgement and minimum-ISR requirements apply. Therefore, not every successful send waits for all replicas. Check the current eligible-leader-replica feature configuration as well as the acknowledgement policy.
The KRaft controller manages partition leadership and replica metadata. On failure, a safe eligible replica can be elected; having any arbitrary copy is insufficient. Unclean election can lose acknowledged records. Consumers normally fetch leaders, although follower fetching can be configured.
Changing an existing partition's replication factor uses replica reassignment, rather than treating it as an ordinary scalar topic configuration change. Verify assignment, catch-up, fault-domain placement and remaining capacity before removing an old copy.
Monitor under-replicated/offline partitions and replication lag, and rehearse broker failures. Replication provides resilience under specified assumptions; it does not undo deletion or protect every replica from a correlated disaster.
Replication design, producer acknowledgements, replica reassignment