Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What is consumer lag in Kafka, how is it measured, and which tools or metrics would you use to watch it for a Spring Boot consumer?

Consumer lag is how far a consumer group is behind the end of a partition: the partition's latest offset minus the group's committed offset, or its current position. We can see it per partition with kafka-consumer-groups.sh --describe, and in a Spring Boot consumer the Kafka client's metrics such as records-lag-max are exposed through Micrometer automatically. Because a number of records means little on its own, it is better to watch time lag, how old the oldest unprocessed record is, and to alert on that or on a growing trend rather than on a fixed offset count.

Why this question is asked

Lag is the first number anyone looks at when a Kafka consumer seems slow, and it is the main signal that a consumer is keeping up. It is also easy to misread: 10,000 records of lag can be a few milliseconds of work or several hours. Interviewers ask this question to check that we know how lag is defined and measured, and how to turn it into useful monitoring. In this answer, we will define lag precisely, measure it from the command line, see how Spring Kafka exposes it through Micrometer, look at external lag monitors and time lag, and finish with how to alert on it.

1What Lag Means, Precisely

Every partition has a log end offset, the offset that the next record written to it will get. A consumer group has, for each partition, a committed offset, the next offset it will read after a restart, and while running, a current position, the next offset it will fetch. Lag is the distance between the end of the log and the group.

There are two common versions. Committed lag is log end offset minus committed offset; it is what external tools see, because they can read committed offsets from the brokers. Consumer-side lag is log end offset minus the consumer's current position; it is what the client itself reports, and it is usually a little smaller because the consumer may have fetched records it has not committed yet. For consumers using read_committed, the end is the last stable offset rather than the log end, because records of open transactions cannot be read yet.

Lag on one partition
MeasureOffsetMeaning
Log end offset10,500Next record written gets this offset
Consumer position10,320Next record the consumer will fetch
Committed offset10,200Where the group restarts after a crash
Consumer-side lag18010,500 - 10,320
Committed lag30010,500 - 10,200 (what external tools see)

2Measuring Lag From the Command Line

The quickest look is the kafka-consumer-groups.sh tool that ships with Kafka. With --describe and a group id, it lists every partition the group reads with its current committed offset, the log end offset, the difference as LAG, and which consumer owns it.

YAML
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --group order-service
# GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID
# order-service orders 0 10200 10500 300 consumer-1-...
# order-service orders 1 9870 9874 4 consumer-2-...
# order-service orders 2 10011 10011 0 consumer-3-...

Notice that lag is per partition. A total across the topic can hide the real story: one partition with 300,000 records of lag and eleven with none points to a hot key or a stuck record, not to a lack of consumers. The CURRENT-OFFSET column here is the committed offset, so this tool shows committed lag.

3Lag Metrics in a Spring Boot Consumer

The Kafka consumer client computes its own lag from each fetch and publishes it through its metrics: records-lag per partition, records-lag-max, the highest lag across the consumer's partitions, and records-lag-avg. Spring Kafka connects these client metrics to Micrometer, and Spring Boot does it automatically when Micrometer is on the classpath, by registering a MicrometerConsumerListener on the auto-configured consumer factory.

So with Spring Boot Actuator and a registry such as Prometheus, the metrics appear without extra code, with tags for the client id, topic and partition. Spring Kafka also records listener timers, how long each record or batch took in our method, which tell us why lag is growing.

Properties
# application.yml
management:
endpoints.web.exposure.include: health, prometheus
# GET /actuator/prometheus (excerpt)
# kafka_consumer_fetch_manager_records_lag_max{client_id="consumer-order-service-1",...} 300.0
# kafka_consumer_fetch_manager_records_lag{topic="orders",partition="0",...} 300.0
# spring_kafka_listener_seconds_count{name="orderListener-0",result="success"} 98123.0

There is one gap: client metrics exist only while the consumer is running. If every instance of the service crashes, the metrics stop, and a dashboard may show the last value or nothing. That is exactly the moment when lag matters most.

4External Lag Monitors and Time Lag

External tools fill that gap. Tools such as LinkedIn's Burrow, kminion or a Prometheus Kafka exporter read committed offsets and log end offsets from the brokers on a schedule, for every group, so they keep reporting lag even when the consumers are down. Many managed Kafka services and observability platforms provide the same view.

They can also estimate time lag. Offset lag counts records; time lag says how far behind the group is in time, for example the age of the record at the committed offset, or an estimate based on the recent write rate per partition. Time lag is often more useful because it matches what the business cares about. 'Order emails are three minutes behind' means something to everyone; '18,000 records' does not, and the same 18,000 records can be one second of evening traffic or an hour of night traffic.

5Alerting on Lag the Useful Way

A fixed threshold on offset lag, such as 'alert above 10,000', is noisy and misleading. During a traffic peak lag rises briefly and recovers, so the alert pages someone for nothing. On a quiet topic, a stuck consumer may stay below the threshold for hours.

Better alerts look at time lag against what the consumer needs, for example 'the order-email group is more than 5 minutes behind for 10 minutes', or at the trend, for example 'lag has grown continuously for 15 minutes on any partition'. Both ignore short spikes and catch real problems. Pair them with an alert when a group has no active members, so a crashed service is not hidden behind stale metrics.

Step throughFrom lag numbers to a useful alert
  1. Collect lag per partitionclient metrics + external monitor
  2. Convert to time lagage of oldest unprocessed record
  3. Time lag above the group's objective for 10 min?
    YesPage the owning teamNoNext check
  4. Lag growing steadily for 15 min?
    YesWarn the owning teamNoNo alert: short spikes recover

4 steps in order. Play them, or step through them one at a time.

6Follow-up questions

Can lag be negative or jump strangely?

Committed lag can look odd when offsets are reset, when a topic's retention deletes records the group has not read, or with transactional topics, where commit markers take offsets that are never delivered as records. A group that is caught up may then show a lag of 1 or 2 permanently. Time-based lag avoids most of this confusion.

Why does lag rise during a rebalance?

During a rebalance, consumers stop fetching while partitions are reassigned, so records keep arriving and lag grows. With frequent rebalances, for example from slow processing that exceeds max.poll.interval.ms, lag can grow without the consumer ever being truly overloaded.

Should lag be zero?

Not exactly. A healthy consumer always has a small lag, the records written since its last fetch or commit. What matters is that lag stays bounded and the time lag stays within what the business needs.

7Conclusion

In this answer, we saw that consumer lag is the difference between a partition's latest offset and the group's committed offset or current position, measured per partition. kafka-consumer-groups.sh --describe shows it from the command line, and Spring Boot exposes the client's records-lag metrics through Micrometer automatically. External monitors keep reporting when consumers are down and can estimate time lag, which is usually more meaningful than offset counts, so alerts should use time lag or a growing trend rather than a fixed number of records.

What to say in the interviewAbout 90 seconds aloud

Open with

Consumer lag is how far a consumer group is behind the end of a partition. Precisely, it's the log end offset minus the group's committed offset, or minus the consumer's current position if we ask the client itself, and for read_committed consumers the end is the last stable offset.

Then, if they want more

It's always per partition, and I look at it per partition because one partition lagging tells a very different story from all of them lagging. From the command line, kafka-consumer-groups.sh --describe --group shows committed offset, log end offset and lag for each partition.

In a Spring Boot consumer, the Kafka client already computes records-lag and records-lag-max, and Spring Boot registers a Micrometer listener on the consumer factory, so with Actuator and Prometheus those metrics show up automatically, along with Spring Kafka's listener timers.

Because client metrics disappear when the consumers are down, I'd also run an external monitor like Burrow or a Kafka exporter that reads committed offsets from the brokers, and that can also estimate time lag.

Time lag, how old the oldest unprocessed record is, is more useful than an offset count, because ten thousand records can be a second or an hour. So I'd alert on time lag against a freshness target, or on a steady growing trend, not on a fixed offset number, plus an alert if the group has no members.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is consumer lag in Kafka, how is it measured, and which tools or metrics would you...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/31db86eebf/