Kafka
Consumer Lag
IT Solutions
Data Management
Negative Lag Resolution

How to fix negative consumer lag in Kafka

Codemia Knowledge Hub ·

Negative consumer lag means the consumer's current offset is ahead of the latest offset in the log. The usual fix is to confirm the real offsets with the Kafka CLI, check the topic's retention settings, and reset the consumer group's offsets if they are wrong.

What negative lag means

Consumer lag is the difference between the last message produced (the latest offset in the partition) and the last message consumed (the consumer's current offset). It normally tells you how far a consumer is behind. A negative value says the consumer is past the end of the log, which should not happen in a healthy setup.

Common causes

  1. Topic deletion or log compaction: if retention or deletion removes older messages, the producer side offset can reset or decrease.
  2. Offset resets: a consumer may have its offset moved to a newer value, either manually or through a configuration error.
  3. Topic or partition misconfiguration: wrong settings can make topic offsets decrease or be misreported.
  4. Monitoring tool errors: the tool showing the lag may calculate it wrongly because of bugs or stale data.

Step 1: Verify consumer and producer offsets

Check both offsets directly from Kafka:

bash
1# To check consumer offset
2kafka-consumer-groups --bootstrap-server <host:port> --group <consumer-group-id> --describe
3
4# To check producer offset (latest offset in log)
5kafka-run-class kafka.tools.GetOffsetShell --broker-list <host:port> --topic <topic-name> --time -1

Step 2: Review the topic configuration

Make sure retention policies and partition settings match what you expect:

bash
# Check topic configuration
kafka-configs --bootstrap-server <host:port> --entity-type topics --entity-name <topic-name> --describe

Step 3: Reset the consumer group's offsets

If the consumer side is misconfigured, fix the group id or offset reset settings, or move the group's offsets explicitly:

bash
# You can change consumer configurations to address offset discrepancies
kafka-consumer-groups --bootstrap-server <host:port> --group <consumer-group-id> --reset-offsets --to-latest --execute --topic <topic-name>

Step 4: Keep monitoring

Watch lag with Kafka's own tools or with an external stack such as Prometheus and Grafana, and adjust configuration based on what you see.

Quick reference

Issue IdentifiedSolutionCommand/Action
Consumer Offset Ahead of ProducerReset Consumer Offsetskafka-consumer-groups --reset-offsets
Incorrect Topic ConfigurationReview & Adjust Topic Settingskafka-configs --describe
Fault in Monitoring ToolsValidate with CLI and Other ToolsUse CLI and cross-check with other monitoring tools

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design