Consumer Groups & Scaling
Scale message processing horizontally with consumer groups while ensuring each message is processed exactly once.
1The Pizza Delivery Analogy
Each driver handles different orders, but they all work for the same shop (group). If one driver is busy, another takes the next order.
A Consumer Group is a set of consumers that work together to process messages from a queue/topic. Each message is delivered to only ONE consumer in the group, enabling parallel processing without duplication.
2How Consumer Groups Work
Each message goes to exactly ONE consumer in the group
Key Rules:
- ✓Each message delivered to ONE consumer per group
- ✓Multiple groups can each receive all messages (pub/sub)
- ✓Consumers in a group share the workload
- ✓If a consumer dies, others in the group take over
3Partitions & Consumer Assignment
In Kafka-style systems, topics are split into partitions. Each partition is assigned to one consumer in the group.
3 partitions → 3 consumers (optimal)
You can't have more consumers than partitions in a group. Extra consumers sit idle. Plan partition count based on expected max consumers.
4Scaling Scenarios
5Rebalancing
When consumers join or leave, partitions are rebalanced across remaining consumers.
Use static membership (group.instance.id in Kafka) for short restarts—consumer rejoins without triggering full rebalance.
6Multiple Consumer Groups
Different groups can independently consume the same messages. Each group tracks its own offset.
All 3 groups receive ALL messages independently