Could anyone please explain and direct me to a link or resource to read about how the Kafka consumers work in below scenarios.
1 consumer-group with 5 consumers and 1 topic with 3 partitions (how Kafka decides)
1 Consumer-group with 5 consumers and 1 topic with 10 partitions (how would Kafka share load)
2 consumer-groups with 1 consumer each and Kafka cluster of 2 servers where one topic is partitioned between node 1 and node 2, how duplications can be avoided when consumers from different groups subscribed to one partition.
The above scenarios may not be the best practice when configuring Kafka, but I'd like to understand how they need to be handled.
It's not Kafka itself to assign partitions, but one of the consumers. The first one joining a consumer group will be elected as sort of "leader" and we'll start assigning partitions to the other consumers. Of course, every time a new consumer joins the group, the Kafka "controller" let the leader consumer to know about that and it starts the rebalancing re-assigning partitions. It's the same when a consumer leaves a consumer group.
To confirm that the consumer is involved on that, the strategy for partition assignment is specified by the partition.assignment.strategy property in a consumer configuration. The default value is RangeAssignor while the other ones are RoundRobinAssignor and StickyAssignor.
You can find more about how they work here:
https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/RangeAssignor.html https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/RoundRobinAssignor.html https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/StickyAssignor.html
Said that, what happens specifically in your scenarios?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With