Monitoring consumer lag

Queues, Kafka and event-driven systems Mid-level Python 3.13+ PostgreSQL 17+ Reviewed By Best Latest Apps

Predict the output

Partition end offsets and committed offsets for a group. What's the total lag?

Python 3.13
end = {0: 1200, 1: 980, 2: 1500}
committed = {0: 1200, 1: 900, 2: 1100}
print(sum(end[p] - committed[p] for p in end))

Options
Hint 1 of 1

Lag is end minus committed, per partition.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A 480

Correct. 0 + 80 + 400; partition 2 is where the problem is.

Lag per partition is the end offset minus the committed offset: 0, 80 and 400. The total is 480, and per-partition numbers show which partition is stuck.

Why not the others?
  • B 400. Partition 1 is also 80 behind.
  • C 3680. That's the sum of end offsets.
  • D 0. Only partition 0 is caught up.

30-second answer

Measure lag: for each partition, the latest offset minus the group's committed offset, and better, how old the oldest unprocessed message is. Alert when lag in time crosses what the business tolerates and when it keeps growing, not on a fixed message count. Pair it with processing rate and error rate per consumer, so you can tell 'more traffic' from 'consumers stuck'.

Practise saying it · 25 s. No recording, just a timer

How do you monitor lag?

Say your answer out loud, then check which of these points you covered:

  • End minus committed
  • Age of oldest message
  • Alert on growth
  • Per partition

Deep dive

kafka-consumer-groups.sh --describe --group billing shows LAG per partition.

Lag concentrated in one partition points at a hot key or a stuck consumer.

Burrow and exporters feed lag into Prometheus.

For SQS, ApproximateAgeOfOldestMessage is the equivalent.

Common mistakes

  • Alerting only on total message count.
  • No per-partition view.
  • Autoscaling consumers past the partition count.

Senior take & follow-ups

Define lag, prefer time-based, alert on growth, and break it down per partition.

Follow-up questions

Think of your answer first, then open the hint.

  1. Lag in one partition only?

    Show hint

    Hot key or a stuck consumer on that partition.

  2. Messages or seconds?

    Show hint

    Seconds tell you how stale the results are.

Suggest a fix if something here is wrong or out of date.