419 viewsAsked at 2 companies
How did you scale consumers in Kafka? What happens if there are more consumers than partitions?
Asked at
AI answer
In Kafka, messages are distributed across topic partitions. With 6 partitions and 6 consumers in the same group, each consumer usually receives exactly one partition, meaning the load is evenly distributed.
If the number of consumers decreases to 2, then the 6 partitions will be distributed between these two consumers. For example, one might get 3 partitions, and the other — 3. It is important that the number of partitions is always greater than or equal to the number of consumers; otherwise, some consumers will be idle.
Distribution example:
- 6 partitions, 6 consumers: each consumer reads 1 partition.
- 6 partitions, 2 consumers: consumer 1 reads partitions 0,1,2; consumer 2 — 3,4,5.
This distribution ensures parallel data processing and load balancing among consumers.
Also asked at Магнит Тех
Similar questions
- How did you scale Kafka consumers? Based on what criteria?
- What is the optimal number of consumers you consider justified for reading data from Kafka?
- If more consumers are added with a large Kafka lag — will it help? In which cases will it help, and in which will it not? What if there are 16 partitions and 2 consumers?
- How does Kafka scale?
- How many partitions should a Kafka topic have?