node.jsapache-kafkaevent-driven-designkafkajs

How multiple Kafka Consumers in the same consumer group read messages from one partition in the topic?


I would like to know about how the consumers in the same consumer group read the messages from one topic which has only one partition.

For example, I have 3 consumers in one consumer group and that group is polling messages from Topic A which has partition A so if I have 1000 messages coming one by one in the Topic A how it would be delivered to 3 of the consumers.

  1. Would it be like 3 messages will be delivered to 3 consumers parellely and once it's processed by each the another one would be delivered basically will they receive messages paraellely?
  2. Would it be like any one consumer will fetch those messages as there is only one partition ?

Please also suggest me the best architecture approach for above scenario.

Thanks,

I want to process the multiple messages parallelly from one topic which has one partition to 4 consumers.

I am using the kafka structure with NodeJS microservices with kafkajs package.


Solution

  • In your scenario, only one consumer of that consumer group will read the data, most probably the first one you started. I'm not 100% sure as I never tried it out, but I assume the additional consumers will just idle without workload.

    This question is essentially the same as yours.

    If you want to achieve parallelity of consumers, you cannot avoid having multiple partitions, that's the main purpose of the whole partitioning concept.