Skip to main content
InterviewHubPRO
Section Overview
Q27

Question 27 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

54%
Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Handling Consumer Lag: Detection, Diagnosing Root Causes, and Autoscaling Consumer Pods.

senior LevelMost AskedKubernetesSystem Design

In Simple Words: Consumer Lag = Log End Offset (LEO) - Current Consumer Committed Offset. It measures how many records are sitting in the broker unread.

Diagnostic Checklist:

  1. Uneven Lag across Partitions: Caused by a hot partition key (e.g. 80% of traffic using the same customer ID).
  2. Lag growing across all partitions: Consumer processing logic is too slow (slow database queries, external REST calls, CPU starvation).
  3. Autoscaling with KEDA (Kubernetes Event-driven Autoscaling):
    • Deploy KEDA in Kubernetes with a ScaledObject monitoring consumer group lag.
    • When total lag exceeds 5,000 records, KEDA automatically scales consumer pods from 2 to the maximum partition count (e.g. 10 pods for 10 partitions).
    • Note: You can never scale consumer pods beyond the total number of partitions in the topic!