0
0
Kafkadevops~10 mins

Group coordinator in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Group coordinator
Start Consumer Group
Join Group Coordinator
Coordinator Assigns Partitions
Consumer Polls Messages
Heartbeat to Coordinator
Rebalance if Needed
Continue Polling or Leave Group
The group coordinator manages consumer group membership, assigns partitions, and handles rebalances to ensure smooth message consumption.
Execution Sample
Kafka
consumer = KafkaConsumer('topic', group_id='group1')
for message in consumer:
    print(message.value)
This code creates a consumer in a group and continuously polls messages from assigned partitions.
Process Table
StepActionCoordinator ResponseConsumer StateOutput
1Consumer starts and sends JoinGroup requestCoordinator registers consumer in groupJoining groupNone
2Coordinator assigns partitions to consumerSends assignment to consumerAssigned partitionsNone
3Consumer polls messages from assigned partitionsNo direct responseConsuming messagesMessage values printed
4Consumer sends heartbeat to coordinatorAcknowledges consumer is aliveMaintains membershipNone
5Another consumer joins groupTriggers rebalanceRebalancingNone
6Coordinator reassigns partitionsSends new assignmentsPartitions reassignedNone
7Consumer continues polling with new assignmentsNo direct responseConsuming messagesMessage values printed
8Consumer leaves groupRemoves consumer from groupLeft groupNone
9Coordinator triggers final rebalanceReassigns partitions to remaining consumersUpdated assignmentsNone
💡 Consumer leaves group or application stops, ending message consumption.
Status Tracker
VariableStartAfter Step 2After Step 5After Step 6Final
Consumer StateNot startedAssigned partitionsRebalancingPartitions reassignedLeft group
Coordinator Group MembersEmpty1 consumer2 consumers2 consumers with new assignments1 consumer
Key Moments - 3 Insights
Why does the consumer enter a rebalancing state after a new consumer joins?
When a new consumer joins, the coordinator must redistribute partitions to balance load, causing rebalancing as shown in step 5 of the execution_table.
What happens if the consumer stops sending heartbeats?
The coordinator assumes the consumer is dead and triggers a rebalance to assign its partitions to others, maintaining group health (implied between steps 4 and 5).
How does the coordinator know which partitions to assign?
The coordinator uses the group membership and partition info to assign partitions evenly among consumers, as seen in step 2 and step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the consumer receive its partition assignment?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Check the 'Coordinator Response' column for 'Sends assignment to consumer' in the execution_table.
According to variable_tracker, what is the consumer state after step 5?
AAssigned partitions
BRebalancing
CConsuming messages
DLeft group
💡 Hint
Look at the 'Consumer State' row under 'After Step 5' in variable_tracker.
If the consumer stops sending heartbeats, what will the coordinator most likely do next?
ATrigger a rebalance to remove the consumer
BIgnore and continue as normal
CAssign more partitions to the consumer
DSend a message to the consumer
💡 Hint
Refer to key_moments about heartbeat and rebalance behavior.
Concept Snapshot
Group Coordinator manages consumer group membership.
Consumers join group and get partition assignments.
Consumers send heartbeats to stay in group.
Coordinator triggers rebalance on membership changes.
Partitions are reassigned to balance load.
Consumers poll messages from assigned partitions.
Full Transcript
The group coordinator in Kafka manages the consumer group lifecycle. When a consumer starts, it sends a join request to the coordinator. The coordinator registers the consumer and assigns partitions to it. The consumer then polls messages from these partitions. To maintain membership, the consumer sends heartbeats to the coordinator. If a new consumer joins or one leaves, the coordinator triggers a rebalance to redistribute partitions evenly. This ensures all messages are consumed efficiently. If a consumer stops sending heartbeats, the coordinator assumes it is dead and reassigns its partitions to others. This process keeps the group healthy and balanced.