Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Debugging Stalled Consumers: Diagnosing `CommitFailedException`, `poll()` timeout (`max.poll.interval.ms`), and heartbeat threads.
senior LevelCode ExampleSystem Design
In Simple Words: When consumers crash with:
sql
org.apache.kafka.clients.consumer.CommitFailedException: Offset commit cannot be completed since the group has already rebalanced and assigned the partitions to another member.
- Root Cause: The consumer took longer to process a batch of records than
max.poll.interval.ms(default 5 minutes). Kafka assumed the consumer was dead and triggered a rebalance. - Fix:
- Decrease
max.poll.records(e.g. from 500 down to 50) so each batch finishes well within the interval. - Increase
max.poll.interval.msto accommodate long-running processing tasks. - Separate heavy processing onto background threads while the main thread calls
poll()promptly.
- Decrease