Apache Kafka handles data replication by replicating messages from a leader to one or more followers. The leader is responsible for managing the message replication process, while the followers passively replicate the leader.
For example, let’s say there is a Kafka cluster with three nodes, A, B, and C. Node A is the leader and nodes B and C are the followers. When a message is published to the cluster, it is first written to the leader (node A). The leader then replicates the message to the followers (nodes B and C). If the leader fails, one of the followers (node B or C) will be elected as the new leader and will continue to replicate messages to the other followers.