What is a consumer group?
Solution and explanation
What it is
A consumer group is a set of consumers sharing the same group.id that **cooperate to read a topic**. Kafka assigns each partition to exactly one consumer in the group, so the work is divided and each record is processed once by the group.
Topic payments: P0 P1 P2 P3 P4 P5
Group billing-service (3 consumers):
consumer A ← P0, P1
consumer B ← P2, P3
consumer C ← P4, P5
Scaling rules
- Adding consumers (up to the number of partitions) increases parallelism.
- **More consumers than partitions:** extra consumers stay idle (useful only as hot standby).
- If a consumer dies or a new one joins, the group **rebalances** and partitions are reassigned.
Group coordination
One broker acts as the **group coordinator**. Consumers send heartbeats to it; if heartbeats stop (session.timeout.ms) or a consumer does not call poll in time (max.poll.interval.ms), it is removed and its partitions go to others. The group's committed offsets are stored in __consumer_offsets.
Groups as "subscribers"
Each group gets the full stream independently. A queue-style service uses one group with many members; pub/sub is achieved by having several groups.
Inspecting a group
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billing-service
# TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID
# payments 0 15020 15030 10 consumer-A
Summary
A consumer group is a team of consumers that split a topic's partitions between them, giving parallel, load-balanced processing with progress tracked per group.
