Kafka consumer stuck in (Re-)joining group
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a distributed publish-subscribe messaging system that is designed to be fast, scalable, and durable. It is widely used in real-time data pipelines and streaming applications. One of the key components of Kafka is the consumer, which reads records from Kafka topics. However, sometimes consumers can get stuck in a process known as "(Re-)joining group." This article explores the technical reasons behind this issue, the implications for your Kafka consumer operations, and how to resolve or mitigate the problem.
What Does "(Re-)joining Group" Mean?
In Kafka, consumers are typically organized into groups for scalability and fault tolerance. Each group of consumers subscribes to one or more topics, and the group divides the work of processing messages in these topics. The Kafka consumer uses a protocol called Consumer Group Protocol to manage the coordination of consumers. This protocol handles member registration, synchronization, and assignment of partitions among all consumers in the group.
The process of "joining a group" involves the following steps:
- Group Coordinator Discovery: Each consumer group is assigned a broker as the group coordinator.
- Join Group Request: Consumers send a join group request to the coordinator.
- Group Synchronization: Once all the consumers have sent their join requests, the coordinator assigns partitions to the consumers.
The "re-joining" process refers to the reconvening of consumer group members to re-establish group membership and partition assignment, typically triggered by changes like consumer addition, shutdown, or a significant delay in processing that exceeds the session.timeout.ms.
Reasons for Getting Stuck in (Re-)joining Group
Consumer groups might get stuck in the (re-)joining stage due to several issues:
- Network Issues: Network problems between consumers and the Kafka broker can lead to missed or delayed heartbeat messages, which are critical for maintaining group membership.
- High Consumer Latency: If consumers are slow to process messages, they might not respond in time to the broker’s requests, leading the group coordinator to assume they have failed.
- Unstable Consumer Groups: Frequent changes in the number of consumers (due to factors like rolling deployments or consumers crashing) can lead to constant re-balancing.
- Configuration Mismanagement: Incorrectly set configurations like
session.timeout.ms,heartbeat.interval.ms, andmax.poll.interval.mscan lead to unnecessary rebalances or consumer drop-outs from the group.
Resolving "Stuck" Consumer Groups
Here are some strategies for resolving issues where consumers are stuck in a (re-)joining loop:
- Adjust Timeouts and Intervals: Ensure
session.timeout.ms,heartbeat.interval.ms, andmax.poll.interval.msconfigurations are optimally set. A rule of thumb is to have theheartbeat.interval.msto be one third ofsession.timeout.ms. - Review Consumer Workload: If consumers are overloaded and cannot keep up with the rate of messages, consider scaling out the number of consumers in the group or increasing resources (CPU, memory) of existing consumers.
- Improve Network Stability: Examine the network connections between consumers and Kafka brokers for stability and throughput capacity, possibly enhancing network infrastructure.
- Utilize Latest Consumer APIs: Consider updating to the latest Kafka client libraries, as they generally contain improvements and fixes related to consumer group stability.
Summary Table of Key Causes and Solutions
| Issue | Implication | Suggested Solution |
| Network Issues | Delay or loss of heartbeat messages leading to unnecessary rebalances. | Check and enhance network connections. |
| High Consumer Latency | Consumers fail to keep up, causing session timeouts. | Scale out consumers or optimize consumer workload. |
| Unstable Consumer Groups | Frequent rebalances due to changes in consumer count. | Stabilize the consumer environment. |
| Configuration Mismanagement | Improper settings lead to tight timeouts or frequent heartbeats. | Optimize configuration settings. |
Conclusion
Getting stuck in (re-)joining group in Kafka can significantly impact data processing capabilities and throughput. By diagnosing the root causes—be it network issues, consumer performance, unstable environments, or configuration settings—effective strategies can be developed to resolve the underlying issues and ensure smooth Kafka operations.
Related reading
- kafka consumer to dynamically detect topics added
- Kafka consumer unit test with Avro Schema registry failing
- Kafka consumer, very long rebalances
- Kafka Consumer WakeupException Handling Java
- Kafka consumer.poll returns no records
- Kafka Consumer's poll() method gets blocked
- Kafka consumer Want to read same message again if not committed previous messages offset and auto commit is disabled
- Kafka ConsumerGroupState explaination

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.