Skip to content

Troubleshooting · Kafka

Kafka consumer slow? 7 causes, ranked

7 causes, most common first · last reviewed

TL;DR

Most of the time the consumer is not slow at reading from Kafka; it is slow at what it does with each record, usually a database or HTTP call inside the poll loop. Check per-partition lag first: lag on every partition points at processing or parallelism, lag on one partition points at a hot key or a stuck record.

On this page

Quick triage: the first five minutes

  1. Read lag per partition, not just the total. Is it growing on every partition, or on one or two?

    Shell
    kafka-consumer-groups.sh --bootstrap-server broker:9092 \
      --describe --group orders-consumer
    LAG per row. Rows with no CONSUMER-ID are partitions nobody owns right now.
  2. Check the group's state and whether it keeps rebalancing. A group that is always rebalancing consumes almost nothing.

    Shell
    kafka-consumer-groups.sh --bootstrap-server broker:9092 \
      --describe --group orders-consumer --state
    STATE should be Stable. PreparingRebalance or CompletingRebalance again and again is a rebalance loop.
  3. Compare how fast records arrive with how fast the group consumes them, and how long one batch takes to process.

    Metrics
    records-consumed-rate        (consumer-fetch-manager-metrics)
    records-lag-max              (consumer-fetch-manager-metrics)
    time-between-poll-avg / -max (consumer-metrics)
    rebalance-rate-per-hour      (consumer-coordinator-metrics)
    If time-between-poll-max approaches max.poll.interval.ms, processing is the bottleneck.

The causes, ranked

Most common first. The ranking is a judgement from how these failures usually turn out, not a measured statistic.

Most common

1. Each record takes too long to process

What it looks like

  • Lag grows on every partition at roughly the same rate.
  • The consumer's CPU is low; threads spend their time waiting on a database, cache or HTTP call.
  • time-between-poll-avg is high and climbs with load; records-consumed-rate is flat even when more records arrive.

How to confirm it

Time the work between two poll() calls. In a thread dump, the consumer threads sit in JDBC, an HTTP client or a lock rather than in the Kafka client. A trace of one batch usually shows a single slow downstream call repeated per record.

Shell
jcmd <pid> Thread.print | grep -A 15 'org.springframework.kafka\|KafkaConsumer'
Look at what the listener threads are blocked on.

Fix it now

Make the per-record work cheaper: batch database writes, cache lookups, remove synchronous calls you do not need, and cut timeouts on downstream calls so one slow dependency cannot stall a partition for minutes. If the work is inherently slow, add parallelism (see the next cause) rather than making the poll loop wait longer.

Prevent it

Track processing time per record as a metric next to lag. Load-test the consumer at the peak arrival rate, with downstream latency at its slowest normal level, not its average.

Most common

2. Not enough consumers, or not enough partitions

What it looks like

  • Each consumer is busy all the time, and adding work to it only grows lag.
  • You added consumer instances but lag did not move, and some show no partitions in the group description.
  • The topic has few partitions compared with the number of consumers you want to run.

How to confirm it

Count partitions and active members. A group can never have more active consumers than the topic has partitions; extra members sit idle. With Spring Kafka, the number of listener threads per instance is the container concurrency.

Shell
kafka-topics.sh --bootstrap-server broker:9092 --describe --topic orders | head -1
kafka-consumer-groups.sh --bootstrap-server broker:9092 \
  --describe --group orders-consumer --members
PartitionCount against the number of members, and #PARTITIONS per member.

Fix it now

If members are fewer than partitions, add instances or raise per-instance concurrency. If members already equal partitions, add partitions, knowing that this changes which partition each key maps to, so per-key ordering across the change is not guaranteed.

Config
# Spring Kafka: listener threads per instance
spring.kafka.listener.concurrency=6

Prevent it

Choose the partition count for the peak consumer parallelism you expect, not today's. Partitions are cheap to have early and disruptive to add later for keyed topics.

Common

3. The group keeps rebalancing

What it looks like

  • Group state flips between Stable and PreparingRebalance; rebalance-rate-per-hour is high.
  • Logs mention that the consumer poll timeout has expired or that max.poll.interval.ms was exceeded.
  • Commits fail with CommitFailedException because the group has already rebalanced, so the same records are processed again.

How to confirm it

Compare the longest gap between polls with max.poll.interval.ms (default five minutes). If processing one batch can exceed it, the member is removed from the group, its partitions move, and it rejoins: every member pays for every rebalance. Rolling deploys and frequent pod restarts cause the same churn.

Shell
kafka-consumer-groups.sh --bootstrap-server broker:9092 \
  --describe --group orders-consumer --state
# repeat every few seconds and watch STATE and #MEMBERS

Fix it now

Lower max.poll.records so a batch finishes well inside max.poll.interval.ms, or raise the interval if long processing is expected. Do not raise session.timeout.ms to hide slow processing; it only delays detection of members that really died.

Config
max.poll.records=100
max.poll.interval.ms=300000
# Fewer full stop-the-world rebalances (Java client)
partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor
# Optional: static membership, so a restarted pod gets its partitions back
group.instance.id=orders-consumer-0

Prevent it

Use cooperative rebalancing and static membership for consumers on Kubernetes, and alert on rebalance rate, not only lag.

Common

4. One partition gets most of the traffic

What it looks like

  • Lag grows on one or two partitions while the others stay near zero.
  • The consumer that owns the hot partition is saturated; the rest are mostly idle.
  • Adding consumers changes nothing, because one partition can only be read by one member of the group.

How to confirm it

Look at log-end offsets per partition over a few minutes: the hot partition's offset climbs much faster. Then check the record keys producers use; a few heavy keys (one tenant, one popular item, or a null-key bug routed one way) hash to the same partition.

Shell
kafka-get-offsets.sh --bootstrap-server broker:9092 --topic orders
# run twice, a minute apart, and subtract
Older Kafka versions ship this tool as kafka-run-class.sh kafka.tools.GetOffsetShell.

Fix it now

Speed up processing for that partition (the first cause applies with extra force), or move heavy work for hot keys elsewhere. Changing the key only helps new records; the backlog already on the hot partition must still drain there.

Prevent it

Choose keys with enough distinct values for your partition count, and watch the spread of bytes in per partition. If ordering only matters within something smaller than the key, key by that instead.

Less common

5. A bad record is retried forever

What it looks like

  • One partition's committed offset stops moving entirely while others advance.
  • The same exception, for the same offset, repeats in the logs.
  • Lag on that partition grows in a straight line from a specific time.

How to confirm it

Find the offset where the partition stopped (CURRENT-OFFSET in the group description stays the same across runs) and read that record. A record that always fails, a poison message, blocks everything behind it in the partition if the error handler keeps retrying.

Shell
kafka-console-consumer.sh --bootstrap-server broker:9092 --topic orders \
  --partition 3 --offset 184227 --max-messages 1 --property print.key=true

Fix it now

Send the record to a dead-letter topic after a bounded number of retries, then commit past it. In Spring Kafka that is a DefaultErrorHandler with a DeadLetterPublishingRecoverer and a finite back-off.

Java
@Bean
DefaultErrorHandler errorHandler(KafkaTemplate<Object, Object> template) {
  var recoverer = new DeadLetterPublishingRecoverer(template);
  return new DefaultErrorHandler(recoverer, new FixedBackOff(1000L, 3)); // 3 retries, then DLT
}

Prevent it

Treat any unbounded retry in a consumer as a bug. Alert on a partition whose committed offset has not moved for several minutes while its log-end offset has.

Less common

6. Fetch and commit settings waste the round trips

What it looks like

  • Network and CPU on the consumer are low, yet throughput is far below what processing time alone would allow.
  • Many small fetches: a high fetch-rate with a tiny fetch-size-avg.
  • Offsets are committed synchronously after every record, and commit-latency-avg is a large share of each loop.

How to confirm it

Compare fetch-size-avg and records-per-request-avg with your record size. Check whether code calls commitSync() per record, or whether the container commits per record (Spring Kafka AckMode.RECORD).

Fix it now

Commit per batch, or asynchronously with a final synchronous commit on shutdown. Let fetches carry more data per round trip when records are small.

Config
fetch.min.bytes=65536
fetch.max.wait.ms=500
max.partition.fetch.bytes=1048576
# Spring Kafka: commit once per poll, not per record
spring.kafka.listener.ack-mode=batch

Prevent it

Keep client settings in version control with a comment explaining each non-default, and benchmark a change before rolling it out across all consumers.

Rare but nasty

7. The brokers or a quota are holding the consumer back

What it looks like

  • fetch-latency-avg is high and fetch-throttle-time-avg is above zero.
  • Every consumer group on the cluster slows down at the same time, not just yours.
  • Broker network throughput is near the instance's limit while CPU and disk look fine.

How to confirm it

A non-zero fetch-throttle-time-avg means a client quota is throttling you. Check quotas for your client id or user. If no quota applies, look at broker network in and out: consumer reads can be many times producer writes when many groups read the same topic.

Shell
kafka-configs.sh --bootstrap-server broker:9092 --describe \
  --entity-type clients --entity-name orders-consumer
A consumer_byte_rate here caps how fast this client id can read.

Fix it now

Raise or remove the quota if it is wrong. If broker network is saturated, spread partition leadership, move heavy readers off peak, or add brokers or larger network capacity.

Prevent it

Graph bytes out per broker, not only CPU and disk, and count every consumer group that reads each topic when you size the cluster.

See it happen in a real outage

90-second puzzles built from public postmortems. Diagnose it first; the company is revealed after you answer.

Related concepts

FAQ

How do I check Kafka consumer lag?

Run kafka-consumer-groups.sh with --describe and --group. The LAG column is the log-end offset minus the group's committed offset for each partition. For continuous monitoring, use the consumer's records-lag-max metric or an exporter that reads committed offsets from the brokers.

Why does consumer lag keep increasing when the consumers are running?

Records are arriving faster than the group processes them. Usually per-record processing is too slow or there are too few active consumers; check whether the group is stuck rebalancing and whether lag sits on one partition.

Will adding more consumers fix Kafka lag?

Only up to the number of partitions. Each partition is read by one member of a group, so consumers beyond the partition count are idle. If one partition is hot, more consumers do not help at all.

What should max.poll.records be?

Small enough that the slowest realistic batch finishes well within max.poll.interval.ms. The default is 500; if processing one record can take seconds, a much smaller value avoids being removed from the group mid-batch.

All troubleshooting guides

Reference documentation: Apache Kafka documentation: consumer configs ↗ · Apache Kafka documentation: consumer monitoring metrics ↗ · Spring for Apache Kafka reference ↗ · Report a problem

Commands and settings are checked against the documentation linked above. Defaults change between versions; check the documentation for the version you run.