Kafka Consumer Lag
Lag is an offset difference, not elapsed time. Diagnose the trend and business delay using the topic’s record rate and timestamps.
Capture Group State
Section titled “Capture Group State”kafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group orders-consumerkafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group orders-consumer --statekafka-consumer-groups.sh --bootstrap-server kafka:9092 \ --describe --group orders-consumer --members --verboseRecord lag by partition, member assignment, input rate, consume/process rate, rebalance history, deployment changes, and downstream latency.
Interpret the Pattern
Section titled “Interpret the Pattern”| Pattern | Likely cause |
|---|---|
| All partitions grow | Insufficient total capacity or shared dependency |
| One partition grows | Hot key, broker/partition, or assigned member problem |
| Lag grows during rebalances | Member churn or slow callbacks |
| Lag jumps after outage | Expected backlog; measure catch-up rate |
| Offset unavailable | Empty group, missing commit, ACL, or invalid position |
Diagnose
Section titled “Diagnose”Check records consumed, fetch latency, poll interval, processing latency, commit latency, assigned partitions, JVM pauses, CPU throttling, and external calls. Compare input rate with sustained processing rate and calculate whether catch-up meets the required recovery time.
Adding consumers helps only until active members equal partition count. It does not fix a single hot partition, slow external service, or broker-side fetch problem.
Recover
Section titled “Recover”- Restore unhealthy consumers or dependencies.
- Scale active consumers where partitions permit.
- Reduce per-record processing cost or batch external work safely.
- Fix a hot partitioning key or add partitions only after evaluating ordering and key distribution.
- Pause or shed noncritical input only through an approved application mechanism.
Verify
Section titled “Verify”Lag decreases at a predictable rate, processing capacity exceeds arrival rate, members remain stable, commits progress, and end-to-end business delay returns to its objective.
See rebalance storm and offset out of range for related failures.