Bug Days
Developer guide

Diagnose Kafka Consumer Lag and a Stuck Partition

Diagnose Kafka consumer lag with two snapshots: find stalled partitions, unexpected group members, uneven assignments, and possible poison-pill records.

· Updated 8 minute read Kafka consumer diagnostics
Kafka lag growing from 50 to 79 while partition 2 stays committed at offset 9310

Start with the group and topic, then look at every partition. A total lag number hides the useful shape: one partition can be stalled while the others are nearly caught up.

Follow the worked example: open and share this Kafka lag report. It contains fictional data and no credentials. No Kafka cluster or local bridge is needed to read the snapshot.

Compare committed position, partition end, and owner

In the Kafka consumer group analyzer, take a snapshot and watch it for several samples. A committed offset is the group’s restart position, usually the next record after work it has acknowledged. A running consumer may already have fetched or processed beyond its last commit. The lag shown here is the offset gap between the committed position and current partition end, not necessarily an exact count of live messages: compaction and transaction control records can leave gaps. The KafkaConsumer documentation distinguishes current position from committed position.

A two-snapshot example: growing lag versus no commit progress

These snapshots are one minute apart. Compare each partition with itself; offsets from different partitions are not directly comparable. “End” means the next offset after the current end, not the last record’s offset.

PartitionCommit before → afterEnd before → afterLag before → afterFirst lead
012800 → 1284012804 → 128444 → 4Keeping pace
117000 → 1710017010 → 1713010 → 30Progressing, but falling behind
29310 → 93109360 → 938950 → 79No commit progress
32000 → 20442048 → 209248 → 48Unexpected member owns this partition

Partition 1 commits 100 offsets while its end grows by 120, so its gap increases by 20. Partition 2 does not advance from 9310 while 29 more offsets arrive. Partition 3 keeps the same lag but belongs to a member outside the expected deployment. A group-wide lag total would hide those different investigations.

Tell a slow consumer from a stuck one

If the commit advances but the end advances faster, the consumer is falling behind. Look at processing time, downstream dependencies, retry behavior, and partition distribution. If the commit stays unchanged while the end moves, inspect the next available record at the committed position and the previous retained record. A malformed or unexpected message may be a poison pill, but an unavailable database or a paused application can produce the same offset pattern.

The analyzer compares two snapshots and marks stalled or growing lag. Its Compare action reads nearby records through the local bridge. It does not claim to know the last message your application processed successfully.

Choose a sampling interval longer than the normal commit cadence and batch processing time. An unchanged commit between two quick samples can be normal. Conversely, a partition can remain stuck with a nonzero backlog even when no new data arrives; the tool’s “Commit stopped while data arrived” heuristic specifically requires a rising end position, so absence of that flag does not establish health.

If every partition slows together, check shared dependencies, retry storms, CPU pressure, garbage collection, and repeated rebalances. If only one slows, inspect its owner, hot keys, record sizes, and downstream calls. Lag zero also does not prove successful business processing if the application commits before work completes.

Check who joined the consumer group

Group IDs are shared identifiers. Another deployment using the same ID can take some partitions. Enter expected client ID or host patterns, such as checkout-processor* or 10.4.*, and compare the group’s members and assignments. A mismatch is a lead: verify deployment metadata before blaming an unfamiliar IP alone.

Check assignment balance and in-sync replicas too. One member owning more partitions can be legitimate when topic subscriptions differ; missing in-sync replicas point to a separate broker or network issue.

In this example, inventory-worker on 10.8.2.45 owns partition 3 even though the expected deployment uses checkout-processor* and 10.4.*. If another application accidentally reuses checkout-workers, Kafka can distribute partitions to it. The records are not deleted or “stolen”; they may simply be assigned to a consumer whose processing your service never sees.

Confirm the member’s deployment and subscriptions before acting. Client IDs are labels, not authenticated identities, and host changes are normal after redeployments or network translation. Independent applications that each need every record should generally use distinct group IDs. After correcting the configuration, inspect the offsets the unintended consumer committed to decide whether a controlled replay is needed.

Uneven assignment is different from uneven workload

With four partitions and three members, an assignment of 2/1/1 is expected. Equal partition counts still do not mean equal work: a hot key can concentrate most records in one partition, and one partition’s messages may trigger expensive processing. Adding consumers beyond the number of assignable partitions leaves some members idle rather than splitting a single partition’s ordered work.

Partition 2 also has only two in-sync replicas out of three in this sample. That is a broker-health lead, not proof that replication caused the consumer to stop. Correlate broker logs and replication metrics with the same time window.

Compare a possible poison-pill record with its neighbor

Inspect the next retained record at or after committed offset 9310, plus a nearby earlier record. A useful fictional comparison is:

partition 2 / offset 9309:
{"orderId":1028,"status":"paid","amount":19.95}

partition 2 / offset 9310:
{"orderId":1029,"status":"paid","amount":"invalid-number"}

The changed type at amount could break a numeric deserializer. Use the JSON diff checker for structured values and inspect the key, headers, schema identifier, tombstone/null value, and encoding as well. With Avro or Protobuf, use the actual writer schema instead of assuming the payload is JSON.

The earlier record is not automatically the last successful one. Batched commits, filtering, transactions, retention, and compaction break that assumption. Confirm the exception and failing offset in application logs, or reproduce with the same deserializer. A database timeout on an otherwise valid record can look identical in the lag report. Prefer a documented retry or dead-letter workflow to blindly skipping the candidate.

Preview an offset reset before applying it

If an offset change is warranted, stop all consumers in the group and review the old and proposed positions per partition. The Kafka offset reset guide covers all eight modes, selected partitions, UTC timestamps, dry runs, and CSV plans. Moving backward can duplicate side effects; moving forward can skip work. A reset does not fix the underlying deserializer or dependency failure.

Export the partition table before a change. That gives you a record of the previous positions if you need to explain the intervention later. Share a redacted snapshot for collaboration; member hosts and connection credentials are omitted from the link.

Include the sampling interval and application evidence with that snapshot. The share is a point-in-time report, not a live dashboard; a teammate must connect their own bridge to refresh it. Exported reports deserve a separate review before posting publicly because exports and shared snapshots are different representations.

Continue reading