Troubleshooting guide
Kafka consumer lag: how to measure and reduce it
Consumer lag is how far a consumer group is behind the latest message. A steadily growing lag means your consumers cannot keep up with producers.
3 min read10 sectionsUpdated
On this page
# Lag per partition
kafka-consumer-groups.sh --bootstrap-server kafka:9092 --describe --group orders
# Group members and assignments
kafka-consumer-groups.sh --bootstrap-server kafka:9092 --describe --group orders --members --verbose
# Group state: Stable, or stuck rebalancing?
kafka-consumer-groups.sh --bootstrap-server kafka:9092 --describe --group orders --stateFixes
Speed up each message: batch writes, and avoid per-message network calls. Reduce max.poll.records or increase max.poll.interval.ms if handling a batch takes too long. Use cooperative rebalancing and static membership (group.instance.id) to prevent rebalances during rolling restarts. Add partitions when you truly need more parallelism, knowing that key ordering changes for new messages. Send messages that repeatedly fail to a dead-letter topic.
Reading the partition table
If only one partition lags, suspect key skew or a poison message on it. If all partitions lag evenly, overall capacity is too low. If lag rises on every partition held by one consumer, that instance is the problem, perhaps a long GC or a bad host. A CONSUMER-ID shown as blank means nobody owns that partition at all. When deciding how urgent lag is, convert it to time by dividing it by the consumption rate: a million messages can be ten seconds or ten hours of delay.
Catch it automatically
Alert on lag that keeps growing over a window, or on estimated seconds behind. Kafka monitoring charts it per group, and tracing consumer spans in APM reveals what each message spends its time on.
Does adding consumers always reduce lag?
Only up to the number of partitions. Extra consumers sit idle.
What triggers a rebalance?
A consumer joining, leaving, or missing poll deadlines, and changes to the subscribed topics.
Can I increase partitions safely?
Yes, but keyed messages may land on different partitions than before, affecting order.
Related reading
- Node.js event loop lag: how to measure and fix it: Measure and fix Node.js event loop lag: monitorEventLoopDelay, CPU profiles, synchronous code, big JSON and worker threads, with thresholds that matter.
- What is alert flapping?: Alert flapping explained: why alerts fire and resolve over and over, and the fixes that work: sustained conditions, hysteresis, cooldowns and grouping.
- How to reduce First Contentful Paint (FCP): Reduce First Contentful Paint: lower TTFB, remove render-blocking CSS and scripts, load fonts sensibly and measure improvements with real-user data.
- What is a telemetry pipeline?: Telemetry pipelines explained: collecting, processing and routing logs, metrics and traces, redacting sensitive data, cutting volume.
- What is Total Blocking Time (TBT)?: Total Blocking Time explained: long tasks, how TBT is calculated, the 200 ms target in Lighthouse, how it relates to INP and how to break up main-thread work.
- Alerting best practices: Alerting best practices for software teams: alert on symptoms, require persistence, set severities, route to owners and review alerts monthly.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.