---
title: "Kafka consumer lag: why it grows and how it drains"
description: "max.poll.records=2 caps a consumer below the producer rate, so Kafka consumer lag builds and holds near its peak, then drains once the producer stops."
url: https://monedula.dev/kafka-simulator/scenarios/sustained-lag/
---

# Kafka consumer lag: why it grows and how it drains

Scenario 02.3.4 · Sustained consumer lag. Consumer groups · Intermediate · about 3 min · Apache Kafka 4.3.

A consumer capped by max.poll.records cannot keep up with a faster producer, so lag accumulates - then drains once the producer stops.

Run it: https://monedula.dev/kafka-simulator/playground/?scenario=02.3.4

## What you start with

Consumer lag is the gap between the end of the log and a group's position. Here max.poll.records caps the consumer's throughput below the produce rate, so lag steadily accumulates while the producer runs, then drains once it stops.

## Step by step

1. **Ready · lag 0** (t+0.000s): A single consumer with max.poll.records = 2 polls every 600 ms. The producer is about to write ~5 records/sec - faster than the consumer can drain. Press play. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=02.3.4&t=0)
2. **Falling behind** (t+0.700s): Each poll returns at most 2 records, but the producer keeps appending. The committed offset trails the high watermark - lag is building. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=02.3.4&t=1)
3. **Sustained lag** (t+1.900s): The 2-record poll cap can't match the producer's rate, so lag holds near its peak while the producer stays ahead. This is the core lesson: a consumer slower than its producer accumulates sustained lag. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=02.3.4&t=2)
4. **Drained · caught up** (t+4.300s): The producer has stopped. With no new records arriving, the capped consumer finally drains the backlog two at a time and lag returns to 0. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=02.3.4&t=3)

## The takeaway

Lag grows whenever consume rate trails produce rate and only shrinks when the consumer catches up - the core signal for whether you need to scale consumers or speed up processing.

## Configs in this scenario

- [`max.poll.records`](https://kafka.apache.org/43/configuration/consumer-configs/#consumerconfigs_max.poll.records): The most records one poll() returns (default 500); a smaller value shortens the processing between two polls, which keeps a group member inside max.poll.interval.ms.

## Further reading

- [Apache Kafka documentation](https://kafka.apache.org/43/configuration/consumer-configs/#consumerconfigs_max.poll.records)

## Troubleshooting

- [Kafka consumer lag keeps growing: causes and fixes](https://monedula.dev/kafka-simulator/troubleshooting/consumer-lag-keeps-growing/)
