Skip to content

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

Key points

  • The trend matters more than the number.
  • More consumers than partitions adds nothing.
  • Rebalance storms stop consumption entirely.
  • Lag in time is more meaningful to users than lag in messages.

What lag means

For each partition, lag is the log end offset minus the group's committed offset. A burst followed by recovery is normal. Lag that climbs without returning means the processing rate is below the arrival rate.

Common causes

  • Slow processing, usually a database or remote call per message.
  • Too few partitions, limiting parallelism.
  • Frequent rebalances due to consumers exceeding max.poll.interval.ms.
  • Key skew, leaving one partition with most of the traffic.
  • A stuck poison message that is retried forever.

Diagnose it

Look at lag per partition, then at how members are assigned.

bash
# 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 --state

Fixes

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.

Frequently asked questions

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.

  • 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.