What is Kafka consumer lag and how do you monitor it?
Kafka consumer lag is the difference between the latest offset produced to a partition (log-end offset, LEO) and the last offset committed by the consumer group for that partition. It measures how far behind the consumer is from the producer—how many unconsumed messages are waiting.
**How offsets work**: Each partition in Kafka has a monotonically increasing offset. The producer advances the log-end offset with every written message. The consumer reads messages and periodically commits its current offset to the `__consumer_offsets` internal topic. Lag = LEO - committed offset. If the consumer stops or processes messages slowly, lag grows.
**Why lag matters**: A growing lag means the consumer cannot keep up with the producer. In real-time pipelines this means increasing processing delay—messages are being processed later than they were produced. A lag that grows without bound eventually causes backpressure issues, OOM if messages are buffered in memory, or SLA violations. A lag spike after a deployment or scaling event is expected; lag that grows monotonically is a reliability signal.
**How to measure it**: - **kafka-consumer-groups.sh --describe**: CLI tool that outputs group ID, topic, partition, current offset, log-end offset, and lag per partition. Direct and authoritative. - **Kafka JMX metrics**: Brokers expose `records-lag-max` and `records-lag` per consumer group and partition via JMX. Scraped by Prometheus via the JMX Exporter. - **Burrow (LinkedIn)**: Purpose-built lag monitor that analyses lag trends over a sliding window rather than point-in-time values—distinguishes between a consumer that is slow but catching up vs. one that is falling further behind. This is a more actionable signal than raw lag number. - **Confluent Control Center / AWS MSK Monitoring / Datadog Kafka integration**: Managed monitoring solutions for cloud-hosted Kafka.
**Alerting on lag**: Alert on sustained lag growth rate, not absolute lag. A large but stable lag may be fine (batch processor); a small but growing lag is an early warning. Set alert thresholds based on the acceptable processing delay for the use case.
**Remediation**: Increase consumer parallelism by adding consumer instances (up to partition count). Optimize consumer processing (reduce per-message cost). Increase `fetch.min.bytes` / `max.poll.records` for throughput-oriented consumers. If the consumer is persistently unable to catch up, consider adding partitions and rebalancing (requires careful ordering considerations).
Correctly defines lag as LEO minus committed offset, explains why it matters for real-time pipelines, and names at least two monitoring tools or metrics.
Covers definition, measurement methods, Burrow's trend-based approach, alerting on growth rate vs. absolute lag, and remediation options tied to root cause.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment