How it works
The explanation, with examples you can run.
Consumer lag
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billingGROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAGbilling orders 0 3 4 1billing orders 1 1 4 3billing orders 2 0 0 0Lag is the log end offset minus the committed offset, per partition. Read it as a trend: lag that rises during a burst and then drains is the log doing its job as a buffer; lag that climbs steadily means consumers are slower than producers, and they will eventually fall off the end of retention. Lag in time ("how old is the oldest unprocessed record") is easier to alert on than a record count, because a count means different things on different topics. Consumers publish records-lag-max; tools outside Kafka can also compute lag from committed offsets.
Fixes, by cause: add consumers if there are idle partitions to give them; add partitions if every partition already has an owner (keyed topics: plan this); speed up the handler (batching writes, fewer round trips); or deal with a hot key.
Too many partitions
Every partition replica is a directory of segment files and indexes, memory on the broker, entries in the metadata log, and work during leader elections and broker restarts. On the client side, producers keep a buffer per partition and consumers fetch per partition. KRaft raised how many partitions a cluster can manage, but the cost per partition does not vanish. Pick counts from the throughput you need per topic and the consumer parallelism you need, with headroom, rather than a large round number for every topic.
Rebalance storms
A rebalance pauses work on the partitions being moved. With the classic protocol and the old eager assignors, every rebalance stopped the whole group. Common triggers:
- Slow batches. A member that does not call
poll()withinmax.poll.interval.ms(5 minutes) is removed, its partitions move, it comes back and triggers another rebalance. - Missed heartbeats. Long GC pauses or overloaded hosts exceed the session timeout (45 s by default for classic consumers).
- Rolling deploys. Each restart is a leave and a join.
Remedies: smaller max.poll.records or faster processing; static membership (group.instance.id), so a restart within the session timeout keeps its partitions; the cooperative sticky assignor on the classic protocol; or the new protocol (group.protocol=consumer, GA in 4.0), which moves partitions incrementally without stopping the group.
Broker health
kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions ISR smaller than the replica listkafka.server:type=ReplicaManager,name=UnderMinIsrPartitionCount acks=all writes are failingkafka.controller:type=KafkaController,name=OfflinePartitionsCount partitions with no leaderkafka.controller:type=KafkaController,name=ActiveControllerCount exactly one controller should report 1Alongside these: disk usage per broker (a full disk takes a broker down), request latency percentiles, and leader balance. Kafka tries to move leadership back to each partition's preferred replica after a broker returns; kafka-reassign-partitions.sh moves replicas when you add brokers, because new brokers start empty.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.