Home/Learn/Apache Kafka/Consumer Lag Monitoring

Consumer Lag Monitoring

Intermediate
Consumers

Consumer 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.

Kafka — lag 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 partition

Key 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 Aria
1

What is consumer lag in Kafka and how do you measure it?

EasyWipro
2

What happens if a consumer group's lag exceeds the retention period?

MediumConfluent
3

How would you diagnose and fix a growing consumer lag in production?

MediumAmazon
4

How do you expose Kafka consumer lag as a Prometheus metric?

HardLinkedIn
5

How would you design an alert for Kafka consumer lag?

HardNetflix

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.

Loading discussion…