I'm wondering what would be a good approach to configure the amount of partitions in relation to the max number of horizontally scaled instances.
Suppose I have one topic with 6 partitions.
I have one application that uses the ConcurrentKafkaListenerContainerFactory
with setConcurrency
of 6.
That would mean I have will have 6 KafkaMessageListenerContainer
each using one thread and consuming messages from all of my partitions spread out evenly.
If the above is correct then I was wondering what would happen if I scale the app horizontally by adding another instance ? If the new instance would have the same configuration of a concurrency of 6 and ofcourse the same consumer group I believe the 2nd instance will not be consuming any messages. Because no rebalance will happen because each existing consumer will have one partition assigned to it.
But what if we go back to the first example and have 6 partition with one instance having a concurrency of 3 then each consumer thread/KafkaMessageListenerContainer
will have 2 partitions assigned.
If we scale this app (same consumer group id and also a concurrency of 3) I believe that a rebalance will happen and both instances will individually be consuming from 3 partitions.
Are these assumptions correct and if not how should you handle such a case ?
question from:https://stackoverflow.com/questions/65946520/scale-spring-kafka-consumers-app-horizontally