Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Balance 1-Topic Kafka Cluster

Tags:

apache-kafka

We are in the process of designing a Kafka Cluster (at least 3 nodes) that will process events from an array of web servers. Since the logs are largely identical, we are planning to create a single Topic only (say - webevents)

We expect a lot of traffic from the servers. Since there is a single topic, there will be a single leader broker. In such a case how will the cluster balance the high traffic? All write requests will always be routed to the leader broker at all times and other nodes might be underutilized.

Does a external hardware balancer help solve this problem? Alternately, can a Kafka configuration help distribute write requests evenly on a 1-topic cluster?

Thanks, Sharod

like image 436
Sharod Avatar asked May 25 '17 19:05

Sharod


1 Answers

Short answer: a topic may have multiple partitions and each partition, not topic, has a leader. Leaders are evenly distributed among brokers. So, if you have multiple partitions in your topic you will have multiple leaders and your writes will be evenly distributed among brokers.

You will have a single topic with lot of partitions, you can replicate partitions for high availability/durability of your data.

Each broker will hold an evenly distributed number of partitions and each of these partitions can be either a leader or a replica for a topic. Kafka producers (Kafka clients running in your web servers in your case) write to a single leader, this provides a means of load balancing production so that each write can be serviced by a separate broker and machine.

Producers do the load balancing selecting the target partition for each message. It can be done based on the message key, so all messages with same key go to the same partition, or on a round-robin fashion if you don't set a message key.

enter image description here

Take a look at this nice post. I took the diagram from there.

like image 138
Luciano Afranllie Avatar answered Nov 03 '22 01:11

Luciano Afranllie