Multi-Replica
The multi-replica design can enhance the availability and reliability of the system.
Replicas are evenly distributed across the entire cluster. The following algorithm is for replicas:
1. Sort all brokers (assuming there are n brokers in total) and unallocated partitions.
2. Assign the i-th Partition to the (i mod n)-th Broker.
3. Assign the j-th Replica of the i-th Partition to the ((i + j) mod n)-th Broker.
Leader Election Election Mechanism
TDMQ for CKafka dynamically maintains an ISR (in-sync replicas) in ZooKeeper. All replicas in the ISR are keeping up with the Leader. Only members in the ISR may be elected as the Leader.
Assume there are f + 1 replicas in ISR, one Partition can ensure that committed messages are not lost.
Tolerate the failure of f Replicas.
Assume there are a total of 2f + 1 Replicas (including Leader and Follower), at least f + 1 must be ensured before commit.
Replica After replicating the message, to ensure that a new Leader is correctly selected, the number of failed Replicas cannot exceed f.