Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Kafka is each message replicated across all partitions of a topic?

Tags:

apache-kafka

If a topic has 4 partitions, and a publisher sends a message to the topic, will that same message be replicate across all four partitions or only one?

like image 355
Zuriar Avatar asked Jun 27 '17 18:06

Zuriar


2 Answers

Partitioning and replication are two different things.

Partitioning is for scalability. A topic is partitioned in one or more partitions distributed on different brokers so that more consumers can connect to these brokers in order to receive messages sent to the same topic but from different partitions. Increasing partitions increases scalability and the possibility to have more consumers to get messages from the same topic. Answering your question, each message sent to a topic comes into only one partition (of the topic itself).

Replication is for fault-tolerance. You can specify a replication factor on topic creation and it means that every partition for that topic is replicated more times on different brokers. One replica is the "leader" where producer sends and consumer gets messages; other replicas are "follower" which have copies of messages from the "leader" replica. If the broker which handles the "leader" replica goes down, one of the "follower" becomes leader.

like image 103
ppatierno Avatar answered Sep 23 '22 15:09

ppatierno


Replication does not occur across partitions. Each message goes into a single partition of the topic, no matter how many partitions the topic has.

If you have set the replication-factor for topic to a number larger than 1 (assuming you have multiple brokers running in the cluster), then each partition of the topic is replicated across those brokers.

like image 24
vahid Avatar answered Sep 20 '22 15:09

vahid