Video in progress
What is consumer lag, and how do you monitor it?
Lag is the difference between the partition's latest offset and the offset the consumer group has committed, in other words the number of messages not yet processed. If it keeps growing, the consumer can't keep up with the write rate.
📖 Answer
A quick check with the CLI:
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --group payment-service
# TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG
# payments 0 1520 1523 3
# payments 1 980 15400 14420
In this example partition 1 is the problem: either it gets more messages than the others (a hot key), or the pod reading it is stuck.
On prod you need monitoring, not the CLI: Kafka Exporter or Burrow into Prometheus, then a graph and an alert in Grafana. There's also a records-lag-max metric on the consumer side, which Micrometer exposes automatically in Spring Boot.
The trend matters more than the absolute value of lag. A constant lag of 500 can be perfectly normal. Growing from 0 to 50,000 in 10 minutes means someone needs to be woken up.
Sign up to mark studied questions and save your progress.