Kafka HA
Brokers
Minimum Requirement
High Availability
Kafka Configuration

In Kafka HA, why minimum number of brokers required are 3 and not 2

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

In a high availability (HA) setup for Apache Kafka, a central consideration is the reliability and robustness of the message streaming capabilities even during failures or maintenance activities. Kafka relies on distributed systems principles to achieve high availability and data durability. Establishing the minimal number of brokers becomes vital in architecting a resilient Kafka cluster. The use of three brokers, rather than two, is fundamental for a robust Kafka deployment due to reasons rooted in fault tolerance, election algorithms, and performance considerations.

Understanding Kafka's Broker and Zookeeper Interaction

Kafka uses a set of servers called brokers for managing the storage of messages in topics. Topics are split into partitions, with each partition potentially having multiple replicas across various brokers to ensure availability and redundancy. Kafka Brokers work in conjunction with Apache ZooKeeper, which is a centralized service for maintaining metadata about the Kafka cluster and performing leader election for partitions.

Leader election is crucial because the leader handles all read and write requests for the partition while followers copy data from the leader. If a leader fails, one of the followers is elected as the new leader. For these elections and overall cluster coordination, having a stable ZooKeeper ensemble is critical.

Fault Tolerance

Fault tolerance refers to the system's ability to continue functioning in the event of component failures. Consider a scenario with two brokers:

  • Two Brokers: If one broker fails, the cluster continues to function with the remaining broker. However, if the second broker also encounters issues—even briefly— the entire system becomes unavailable.
  • Three Brokers: If one broker fails, two brokers remain operational, which not only provides better load handling but also an additional layer of redundancy. Even with one broker down, the system can tolerate another failure for a brief period, making maintenance and upgrades easier without impacting availability.

Quorum and Majority Voting

The concept of quorum is integral to distributed systems and affects how Kafka’s ZooKeeper handles leader elections and commit of records. A quorum is a majority of voting nodes (in this case, brokers), where:

Quorum size=(Total number of nodes2)+1\text{Quorum size} = \left(\frac{\text{Total number of nodes}}{2}\right) + 1

For effective fault tolerance, the write and read requests must pass through a majority of nodes. This ensures that the system's state is consistent and avoids "split-brain" scenarios, where two separate portions of the cluster believe they are both active and can lead to data inconsistencies.

  • Two Brokers: With two brokers, both must be operational to form a majority (quorum of 2). This setup offers no fault tolerance as the failure of one broker brings down the system.
  • Three Brokers: With three brokers, a majority requires two. Thus, the system can sustain the failure of one broker and still operate, ensuring higher availability.

Examples and Performance Implications

In practice, deploying three Kafka brokers enhances performance under load and during failovers. With three brokers, Kafka can handle one broker being down for maintenance or unexpected failure while still processing messages. This failsafe is crucial for systems requiring high availability such as financial transaction platforms or real-time data analytics systems.

Summary Table

Number of BrokersQuorum SizeFault ToleranceCluster Availability During Failures
22NoneUnavailable with 1 broker down
321 brokerAvailable with 1 broker down

Additional High Availability Considerations

Beyond the number of brokers, ensuring high availability in Kafka also involves:

  • Data replication strategies: Planning the correct number of partitions and replicas (setting replication factor).
  • Quality of service: Balancing between consistency, availability, and partition tolerance to meet specific application needs.
  • Regular maintenance: Scheduled checks and updates for brokers and ZooKeeper ensemble to prevent unexpected failures.

In conclusion, utilizing three brokers in Kafka’s architecture is essential for creating a resilient, high availability environment. This setup safeguards against common failure scenarios and ensures continuous data availability and consistency, which are critical for maintaining real-time processing and decision-making capabilities in distributed systems.


Course illustration
Course illustration

All Rights Reserved.