Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Kafka distributes the topic partitions among the brokers

I have 3 Kafka brokers in 3 different VMs, with one additionally running a Zookeeper. I now create a topic with 8 partitions. The Producer pushes messages to these group of brokers on the created "topic".

  • How does the Kafka distribute a topic and its partitions among the brokers?
  • Does the Kafka redistribute the topic when a new Kafka Broker joins a cluster?
  • Can the topic partition be increased after the topic was created?
like image 746
Vijay Veeraraghavan Avatar asked Sep 04 '15 07:09

Vijay Veeraraghavan


People also ask

How partitions are distributed in Kafka?

Kafka PartitioningPartitioning takes the single topic log and breaks it into multiple logs, each of which can live on a separate node in the Kafka cluster. This way, the work of storing messages, writing new messages, and processing existing messages can be split among many nodes in the cluster.

How are partitions assigned in Kafka?

The messages in the partitions are each assigned a sequential id number called the offset that uniquely identifies each message within the partition. The Kafka cluster retains all published messages—whether or not they have been consumed—for a configurable period of time.

How is Kafka distributed?

Kafka is a distributed system comprised of servers and clients that communicate through a TCP network protocol. The system allows us to read, write, store, and process events. We can think of an event as an independent piece of information that needs to be relayed from a producer to a consumer.

Can a Kafka broker have multiple partitions of same topic?

Figure 3: Each topic is handled by a single Kafka broker, and can be divided into multiple partitions that can be replicated across multiple brokers. Partitions can be configured to be replicated across the brokers in an Apache Kafka cluster.


1 Answers

  • When you create a new topic, Kafka places the partitions and replicas in a way that the brokers with least number of existing partitions are used first, and replicas for same partition are on different brokers.

  • When you add a new broker, it is used for new partitions (since it has lowest number of existing partitions), but there is no automatic balancing of existing partitions to the new broker. You can use the replica-reassignment tool to move partitions and replicas to the new broker.

  • Yes, you can add partitions to an existing topic.

like image 92
Gwen Shapira Avatar answered Sep 19 '22 18:09

Gwen Shapira