A consumer lag alert fires. The consumers look healthy and CPU is low. How do you investigate?
Sketch your own answer first, then compare it with the one below.
A strong answer
Lag as a single number hides where it sits. First, look per partition. If one partition carries all of the lag and the others are at zero, it is a hot key or a stuck message, and more consumers would not help. Find the key and check the partitioner.
If lag is spread out and the group is rebalancing repeatedly, the cause is usually a consumer taking longer than the poll interval (five minutes by default in the Java client), which gets it evicted. The signs are many rebalance events and offsets that move backwards. A slow downstream call inside the loop is the usual reason, and the fix is smaller batches or a longer interval.
If consumers are idle and lag still grows, check whether they own partitions at all. More members than partitions leaves some idle. Check producers too: a rate jump looks like consumer lag.
Last, compare lag with the retention window. If lag is approaching it, data is about to be deleted unread. That sets the urgency. I would also graph time lag, not just message count.
Sources
- Apache Kafka project (2024). Apache Kafka documentation: consumer configs.
- Jay Kreps, Neha Narkhede, Jun Rao (2011). Kafka: a distributed messaging system for log processing.