Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Consumer Lag Monitoring and Mitigation: Prometheus JMX exporter, Burrow, and scaling partition-to-consumer mapping.
senior LevelSystem Design
In Simple Words: Consumer Lag is the delta between the latest offset written to a partition (Log End Offset) and the latest offset committed by a consumer group:
- Monitoring Tools: Export metrics via Kafka Exporter or Burrow (
kafka_consumergroup_lag). - Mitigation Strategies:
- If lag is isolated to one partition -> Check for hot key skew.
- If lag is spread across all partitions and consumer CPU is 100% -> Increase partition count and add more consumer instances up to total partition count.
- If consumer thread is blocked on slow external database calls -> Decouple consumption from processing using an internal in-memory worker thread pool.