Bird
0
0

Given the following Kafka consumer code snippet, what will happen when two consumers with the same group.id subscribe to the same topic with 4 partitions?

medium📝 Predict Output Q13 of 15
Kafka - Consumer Groups
Given the following Kafka consumer code snippet, what will happen when two consumers with the same group.id subscribe to the same topic with 4 partitions?
consumer1 = KafkaConsumer('my-topic', group_id='group1')
consumer2 = KafkaConsumer('my-topic', group_id='group1')
AEach consumer will receive all messages from all partitions.
BOnly one consumer will receive messages; the other will be idle.
CThe consumers will share the partitions so each gets a subset of messages.
DThe consumers will cause a conflict and fail to consume.
Step-by-Step Solution
Solution:
  1. Step 1: Understand consumer group behavior

    Consumers in the same group share partitions so that each partition is consumed by only one consumer.
  2. Step 2: Apply to given scenario

    With 4 partitions and 2 consumers in the same group, partitions will be divided between them, each getting a subset.
  3. Final Answer:

    The consumers will share the partitions so each gets a subset of messages. -> Option C
  4. Quick Check:

    Same group.id means partition sharing [OK]
Quick Trick: Same group.id consumers share partitions, not duplicate messages [OK]
Common Mistakes:
  • Thinking each consumer gets all messages
  • Assuming conflict causes failure
  • Believing only one consumer works

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes