Kafka consumer lag is growing and the topic retention is 24 hours. You're close to losing messages. What do you do?

IntermediateScenarioData and databases
Answer

Situation read → If lag reaches the retention window, unread messages are deleted. Buy time first, then catch up.

What I'd do →

  1. Check how close you are:
kafka-consumer-groups.sh --bootstrap-server b-1.kafka:9092 --describe --group order-processor
  1. Buy time: increase topic retention temporarily (check broker disk first).
kafka-configs.sh --bootstrap-server b-1.kafka:9092 --alter --entity-type topics \
  --entity-name orders --add-config retention.ms=259200000
  1. Scale consumers up to the partition count; more consumers than partitions sit idle.
  2. Find why it's slow: a slow downstream (DB), a poison message causing retries, or a recent consumer change. Send poison messages to a dead-letter topic.
  3. Long term: alert on lag (and on time lag, not just message count), autoscale with KEDA on lag, and size partitions for peak.

Why → Extending retention protects the data while you fix throughput.

Interview tip → Mention that consumers are capped by partition count; it's the classic scaling ceiling.

All Real-World Interview questions Roadmap: Interview readiness

More on Data and databases