Consumer Lag Monitoring
IntermediateConsumer lag is the gap between the latest produced offset and the committed consumer offset. High lag means consumers are falling behind and SLA breaches are imminent.
Overview
Lag is the most important Kafka consumer health metric. Sustained and growing lag means the consumer cannot keep up and will eventually fall behind the retention window, causing data loss.
Checking Lag via CLI and Programmatically
Use kafka-consumer-groups.sh for ad-hoc inspection and AdminClient for programmatic monitoring.
# Check lag for a consumer group
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--group order-processor --describe
# Programmatic lag check
AdminClient admin = AdminClient.create(props);
ListConsumerGroupOffsetsResult offsets =
admin.listConsumerGroupOffsets("order-processor");
Map<TopicPartition, OffsetAndMetadata> committed =
offsets.partitionsToOffsetAndMetadata().get();
// compare committed offset vs log-end-offset for each partitionKey Points to Remember
- 1Lag = log-end-offset minus committed-offset per partition
- 2Growing lag → consumer is slower than the producer rate
- 3Lag exceeding retention period → consumer will miss messages
- 4Export lag to Prometheus via kafka-lag-exporter
- 5Alert when lag > threshold AND is growing (not just a spike)
Interview Questions
Sign in to ask AriaWhat is consumer lag in Kafka and how do you measure it?
What happens if a consumer group's lag exceeds the retention period?
How would you diagnose and fix a growing consumer lag in production?
How do you expose Kafka consumer lag as a Prometheus metric?
How would you design an alert for Kafka consumer lag?
Ask Aria about Consumer Lag Monitoring
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.