Monedula

Kafka troubleshooting

Consumer lag keeps growing

Kafka symptom

Lag is the distance between a partition's log end offset and the group's committed offset, so lag that only grows means the committed offset advances more slowly than producers write. First check whether every partition grows or only a few: all of them points to throughput, a few points to a stuck member, a hot key, or commits that stopped.

Reproduce it in the playground

The moment it happensSustained lag. t+1.900s

The 2-record poll cap can't match the producer's rate, so lag holds near its peak while the producer stays ahead. This is the core lesson: a consumer slower than its producer accumulates sustained lag.

Open at this step: step 3, Sustained lag

What it means

kafka-consumer-groups.sh --describe prints one row per partition with CURRENT-OFFSET (the group's committed offset), LOG-END-OFFSET and LAG, the difference between the two. When no consumer of the group is running, it prints "Consumer group 'orders-app' has no active members." first, and nothing drains the lag. The consumer's own records-lag-max metric measures the same distance from its current position instead of the committed offset, so the two can disagree: if records-lag-max stays small while the LAG column climbs, the consumer is reading but its commits are not landing. Lag that rises during a burst and drains afterwards is a backlog being worked off. Lag that climbs for as long as producers write means the consume rate is below the produce rate, and it does not recover on its own.

Likely causes, most common first

  1. Consumers are slower than producers. Per-record work is too slow for the incoming rate, typically a synchronous call to a database or an HTTP service for every record. Lag then grows on every partition at a similar rate.
  2. The group cannot use more consumers. Each partition is read by exactly one member of a group, so a group never uses more consumers than the topic has partitions. Members beyond the partition count sit idle, and adding them does not reduce lag.
  3. A stuck or dead member still owns partitions. A consumer blocked in processing keeps heartbeating and keeps its partitions until max.poll.interval.ms expires, when it logs "consumer poll timeout has expired" and leaves the group; a crashed one keeps them until the session timeout. Until then only that member's partitions grow, while the rest of the group stays level.
  4. One partition gets most of the traffic. Records with the same key always go to the same partition. A skewed key distribution puts most writes on one or two partitions, and the single consumer that owns each of them cannot keep up.
  5. Commits stopped. With enable.auto.commit=false and no commit calls, or with commits failing after evictions, the committed offset stays put while records are processed. The LAG column grows, and a restart reprocesses everything since the last successful commit.

How to fix it

What not to do

Configs involved

Reproduce it in the simulator

Sources

Related

All troubleshooting pages