Skip to the page

Common backend failure patterns · mid

Consumer lag and queue backlogs

When a queue consumer falls behind, check lag per partition, the group state and the time per message. A slow side effect inside the poll loop is a common cause, and more consumers do not always help.

The notes

What you must know

  • Check lag per partition (all partitions or one hot one), the consumer group state and rebalances, processing time per message, and the health of what the consumer calls.
  • Rebalancing every few minutes: a consumer took longer than max.poll.interval.ms (5 minutes by default) between polls, so it was removed from the group. Its partitions move, and its uncommitted batch is processed again, which sends duplicates.
  • A slow downstream (for example an email provider at 1.8 s a call) makes a batch of 500 take about 15 minutes, far more than 5.
  • In a group each partition is read by at most one consumer. With 12 partitions, consumers 13 to 24 sit idle and only add rebalances.
  • Right now: smaller batches (max.poll.records), a timeout on the slow call, move the slow side effect to its own topic or queue.
  • Fix: a fast poll loop, bounded concurrency inside a partition that keeps per-key order, an idempotent consumer (dedupe by event id), and a dead-letter topic for bad messages.
  • Kafka 4.0 and later has the new consumer group protocol (KIP-848). ZooKeeper is gone; Kafka 4 runs in KRaft mode only.
  • Alert on lag measured as time, not only as a count of messages.

The red pen

Common traps: mistake → fix

  • Mistake: Add more consumers to catch up

    Fix: only up to the partition count; extra consumers are idle.

  • Mistake: Lag growing means the consumer is down

    Fix: it may be running but slow, or rebalancing.

  • Mistake: At-least-once delivery means no duplicates

    Fix: redelivery is normal; handlers must be idempotent.

Easy to hard

Questions interviewers ask, easy to hard

  1. Kafka consumer lag keeps growing. What do you check?
  2. Why would consumers rebalance every few minutes?
  3. We have 12 partitions and 24 consumers. What does that mean?
  4. How do you handle one bad message that blocks a partition?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview