Exp 04 // Cluster Fault Tolerance
Start a 3-node Kafka cluster. Create a topic with a Replication Factor of 3. Then, crash the Leader Broker and watch how the remaining nodes elect a new leader without dropping data!
Kafka clusters provide fault tolerance through data replication. A topic with a Replication Factor of 3 stores copies of every message on 3 different brokers. One broker acts as the Leader, serving all read/write requests, while the other two are In-Sync Replicas (ISR). If the leader crashes, the cluster instantly promotes a new leader.
kafka-topics.bat --create --topic ha-topic --partitions 1 --replication-factor 3
Make sure all 3 brokers are running first (click Start Broker on all).
kafka-topics.bat --describe --topic ha-topic
Check the output to see who is the Leader and the ISR.
kafka-console-producer.bat --topic ha-topic
Look at the diagram to see which broker is the Leader. Click its Crash button.
kafka-topics.bat --describe --topic ha-topic
A new leader was elected! Notice the ISR list updated.
As long as one replica from the ISR is alive, your data is safe and the cluster stays available!