Learning center

Is Kafka consumer lag growing because consumers stalled or are slow?

Kafka consumer lag grows when a group's committed offset stops moving, or moves more slowly than producers write to the log end. Describe the group twice a few minutes apart and compare each partition's offsets: the pattern of which partitions moved, and who owns them, tells the cases apart.

Lag means one of three things#

Lag on a partition is the distance between the group's committed offset and the partition's log end offset. The alarm only says that distance grew. The causes behind it are different:

  • Stalled: nobody owns the partition. The group has no active members, or a partition is not assigned to any of them. Its committed offset stays put.
  • Stalled: one consumer is stuck. A member owns the partition and is still in the group, but it commits nothing: it is blocked on one record, waiting on a dependency, or its processing thread is wedged while heartbeats continue.
  • Slow: the offset moves, the log end moves faster. Consumers are working, but throughput fell (a slower database or API behind them, fewer members) or the produce rate rose. If only some partitions fall behind, the load or the consumers are uneven.

Why they look alike#

A lag chart summed over the group rises the same way in all three. Even per partition, one reading cannot separate them: a high LAG says nothing about whether CURRENT-OFFSET moved in the last minute. And CURRENT-OFFSET is the group's committed offset, not the record a consumer is processing now, so a consumer that commits rarely looks stalled between commits. With the Java client's defaults (enable.auto.commit true, auto.commit.interval.ms 5000), commits arrive every few seconds while the consumer is polling. Consumer configs · ConsumerGroupCommand source

Describe the group twice#

kafka-consumer-groups.sh --describe is read-only. It prints, per partition, CURRENT-OFFSET, LOG-END-OFFSET, LAG, and the CONSUMER-ID, HOST and CLIENT-ID of the member that owns it. A partition with a committed offset and no owner shows - in the consumer columns. Basic Kafka operations · ConsumerGroupCommand source

bin/kafka-consumer-groups.sh --bootstrap-server BROKER:9092 --command-config CLIENT_PROPERTIES \
  --describe --group GROUP > describe-1.txt
# wait two or three minutes
bin/kafka-consumer-groups.sh --bootstrap-server BROKER:9092 --command-config CLIENT_PROPERTIES \
  --describe --group GROUP > describe-2.txt

If the group is empty, the tool prints Consumer group 'GROUP' has no active members. If it is mid-rebalance, it prints Warning: Consumer group 'GROUP' is rebalancing. A group that keeps printing the second line belongs in a consumer rebalance loop. ConsumerGroupCommand source

Two more read-only views help. --members --verbose lists each member with its partition count and assignment, which shows a member that owns many hot partitions or none. --state prints the coordinator, the assignment strategy, the group state and the member count. With the consumer rebalance protocol, the admin client needs DESCRIBE access to every topic the group subscribes to. Basic Kafka operations

bin/kafka-consumer-groups.sh --bootstrap-server BROKER:9092 --command-config CLIENT_PROPERTIES \
  --describe --group GROUP --members --verbose
bin/kafka-consumer-groups.sh --bootstrap-server BROKER:9092 --command-config CLIENT_PROPERTIES \
  --describe --group GROUP --state

Leave --reset-offsets and --delete alone while you diagnose. Both change the group.

Read the two snapshots#

For each partition, compute how far CURRENT-OFFSET and LOG-END-OFFSET moved between the two reads.

Consumer columnsCommitted offset movedPoints to
-NoPartition unassigned or group empty
One memberNo, on its partitions onlyThat consumer is stuck
Members presentYes, less than log end, on all partitionsConsumers too slow overall
Members presentYes on most, much less on a fewSkew: hot partition or slow member

For a stuck consumer, look at that host's logs and the Java client's own metrics. last-poll-seconds-ago and time-between-poll-max (under kafka.consumer:type=consumer-metrics) show whether the application is still calling poll(). A consumer that stops polling for longer than max.poll.interval.ms, 300000 ms by default, leaves the group, and its partitions move to another member. A partition whose offset is frozen while its owner stays in the group usually means the owner is still polling but not committing past one record. Kafka monitoring · Consumer configs · KafkaConsumer

For skew, check whether the slow partitions share an owner (one bad host or container) or follow the data (a key that sends most traffic to one partition). --members --verbose answers the first; the per-partition log end growth answers the second.

A worked example: two lag alarms#

This example is illustrative. The fictional consumer group orders-indexer reads the six-partition topic orders with three members. Both incidents start with a lag alarm at 14:10 UTC.

In the first incident, the two reads, three minutes apart:

PartitionOffset movedLog end movedOwner
0, 102,100 eachorders-indexer-2 on 10.0.4.17
2 to 52,050 to 2,1102,050 to 2,120members 1 and 3

Only the partitions owned by member 2 are frozen, and member 2 is still in the group. Its log shows the same record at offset 88,412 on partition 1 failing deserialization and being retried in a loop since 14:01. The partitions are not short of consumers; one consumer is stuck on one record. Restarting it will hit the same record. Skip or park that record in the consumer, then let it continue.

In the second incident:

PartitionOffset movedLog end movedOwner
0 to 5600 to 7002,050 to 2,150members 1 to 3, two each

Every partition moves at about a third of the produce rate. Nothing is stuck. The members' traces show each record now waits on a search cluster that answers in 900 ms instead of 150 ms since 14:00. The lag is a downstream latency problem: is the latency the client's or the server's?

Limits#

CURRENT-OFFSET is what the group committed, so applications that commit manually and rarely can look stalled while working, and applications that commit before processing can look healthy while records fail. The tool reads the group coordinator and the partition leaders at the moment you run it; a rebalance in between changes owners.

How to size a group or add backpressure is a design question outside this guide. If the lag began with a consumer release, compare the old and new revisions first. Other dependency failures are covered in diagnosing runtime dependency failures.

Questions#

What is the difference between CURRENT-OFFSET and LOG-END-OFFSET?

CURRENT-OFFSET is the offset the group last committed for the partition. LOG-END-OFFSET is the end of the partition as the tool reads it at that moment. LAG is the difference between them.

Why does a partition show a dash as its consumer?

The group has a committed offset for that partition but no active member owns it. Either the group has no members, or the partition was not assigned, for example during a rebalance.

Will adding consumers fix a stalled partition?

Not if one record is blocking it. Each partition is assigned to exactly one consumer in the group, so another member that takes it over meets the same record. More consumers help only when every partition is moving and the group is too slow overall.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading