Monedula

Scenario 02.3.4 · Sustained consumer lag

Kafka consumer lag: why it grows and how it drains

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 this scenario in the playground

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: step 3, Sustained lag

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: step 1, Ready · lag 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: step 2, Falling behind
  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: step 3, Sustained lag
  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: step 4, Drained · caught up

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

Embed this scenario

Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.

<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=02.3.4" title="Kafka Simulator: Sustained consumer lag" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/sustained-lag/">Kafka consumer lag: why it grows and how it drains</a></p>

Further reading

Apache Kafka documentation

Troubleshooting

More in Consumer groups

All scenarios