The Troubleshooting and Upgrade Playbook

The Troubleshooting and Upgrade Playbook in Apache Kafka: Kafka incidents repeat. The same eight or nine symptoms account for most pages, and each has a short…

Kafka incidents repeat. The same eight or nine symptoms account for most pages, and each has a short list of causes. This topic is the reference you want open at 3am.

First five minutes

Resist the urge to change settings. Establish where the problem lives.

1. Is anything offline?
     kafka-topics.sh --describe --unavailable-partitions
2. Is durability at risk?
     kafka-topics.sh --describe --under-replicated-partitions
3. Is it one group, one topic, or everything?
     kafka-consumer-groups.sh --describe --group <g>   (look PER PARTITION)
4. Is it produce-side or consume-side?
     producer error/retry rate vs consumer lag trend
5. What changed?
     deploys, partition count changes, new consumer groups, backfills

Question 3 does most of the work. A problem in one group is an application problem; a problem across all groups on one broker is a broker problem; a problem everywhere is a cluster or network problem.

Symptom to cause

SymptomLikely causesWhat to checkFirst action
Lag rising steadily on all partitions of one groupConsumers slower than producers; downstream dependency slow; too few partitions for the workPer-record processing time; partition count versus instance countSpeed up processing or add partitions (mind the key-mapping trap)
Lag rising on one partition onlyKey skew / hot key; one wedged consumer instance; one slow brokerPer-partition lag; key distribution; that instance's logsFix the key granularity; restart or replace the stuck instance
Lag rising while consumers look idleMore consumer instances than partitions; consumer paused; deserialisation loopGroup describe: are some members assigned nothing?Stop over-scaling; align instance count to partitions
Rebalance storm: group rebalances constantly, little progressProcessing exceeds max.poll.interval.ms; frequent pod restarts; session.timeout.ms too tight for GC pausesBatch duration versus max.poll.records; restart events; GC logsLower max.poll.records first; then static membership and cooperative rebalancing
Under-replicated partitions non-zero and sustainedSlow or failing broker; disk saturation; network between brokers; replica fetcher starvationWhich broker leads the affected replicas; disk and network on itInvestigate that broker before touching topic config; you are one failure from write rejection
Frequent ISR shrink and expandFollowers repeatedly falling behind: I/O contention, GC pauses, network jitter, or a genuinely overloaded leaderISR shrink rate; broker request latency; disk utilisationRelieve load on the leader broker; check disk before assuming network
Producers get NotEnoughReplicasISR fell below min.insync.replicasUnder-replicated partitions; broker availabilityRestore the missing replica. Lowering min.insync.replicas trades away the durability you asked for
Disk pressure / broker near fullRetention or retention.bytes under-estimated; unexpected volume; a replica catching up; log cleaner not keeping up on compacted topicsPer-topic disk usage; retention settings; log cleaner healthReduce retention on the largest low-value topic, then add capacity. Never delete segment files by hand
Consumer stuck on one record foreverPoison message: deserialisation or business exception thrown in the poll loop with no handlingRepeating identical error, offset not advancingRoute it to a dead-letter topic. Skipping by resetting the offset loses the record silently
Producer send() blocks then throws TimeoutExceptionBuffer exhausted because brokers cannot keep up, or leadership unavailablebuffer.memory, max.block.ms, broker latency, partition leadershipFix the broker side. Raising buffer.memory buys minutes, not a solution
Duplicates downstreamAuto-commit, non-idempotent consumer, or retries without idempotenceCommit strategy; producer enable.idempotenceCommit after processing; make the sink idempotent
New consumer processed nothing historicalauto.offset.reset=latest on a group with no committed offsetsGroup's committed offsetsReset to earliest deliberately, with a plan for the replay load
Everything slow right after a deployEvery instance restarted at once: rebalance plus state restore; new client version behaving differentlyRebalance timing versus deploy timelineRoll deploys; use static membership and persistent state directories
Cluster fine, one client slowQuota throttling; that client's own GC or CPUQuota config for that client.id; throttle-time metricsConfirm throttling before blaming the cluster

Metrics worth alerting on

Broker side (JMX):

MetricMeaningHealthy
UnderReplicatedPartitionsReplicas not caught up0, sustained
OfflinePartitionsCountPartitions with no leader0 always; non-zero is an outage
ActiveControllerCountControllers in the clusterExactly 1 across the cluster
IsrShrinksPerSec / IsrExpandsPerSecReplication instabilityNear zero; repeated cycling is a warning
RequestHandlerAvgIdlePercentSpare request-handling capacityComfortably above zero; approaching 0 means saturation
Produce and fetch request latency (percentiles)Client-visible broker speedStable; watch p99, not the mean
BytesInPerSec / BytesOutPerSecThroughput per brokerBalanced across brokers; imbalance suggests skew or leadership concentration
Log directory free spaceDisk headroomTrend to full measured in days, not percent

Producer side: record-error-rate, record-retry-rate, buffer-available-bytes, request-latency-avg. A rising retry rate with stable success is the early warning before buffers fill.

Consumer side: records-lag-max (per partition, not just the group total), fetch-latency-avg, commit-latency-avg, and rebalance frequency. For Streams, add state-restore progress and dropped-late-records.

The two-signal summary from Module 4 still holds: per-partition consumer lag for application health, under-replicated partitions for cluster durability. If you only get two alerts, take those.

Safe rolling upgrade

The principle: one broker at a time, and never proceed while the cluster is degraded.

 PREPARE
   read the release notes for the exact version jump
   confirm RF >= 3 and min.insync.replicas >= 2 on important topics
   pin the inter-broker protocol version to the CURRENT version in config
   confirm controlled shutdown is enabled
   verify under-replicated partitions = 0 before starting

 FOR EACH BROKER (one at a time):
   ┌─────────────────────────────────────────────┐
   │ graceful shutdown (lets leadership migrate) │
   │ upgrade binaries                            │
   │ start broker                                │
   │ WAIT for under-replicated partitions = 0    │
   │ WAIT for it to resume leadership normally   │
   └─────────────────────────────────────────────┘
   only then move to the next broker

 FINALISE
   second rolling restart to raise the pinned protocol version
   watch client error rates for a full traffic cycle before declaring done

Why the protocol version is pinned first: it lets old and new brokers speak a common protocol during the mixed-version window, so you can roll forward — and roll back — safely. Once you raise it, downgrade is no longer available. That is why it is a separate, second pass.

Two more habits: upgrade brokers before clients as a general rule, and never combine a version upgrade with a configuration change. When something misbehaves you want one variable, not two.

Replacing a broker

Two approaches, and the choice depends on whether you keep the data.

Same broker id, data intact (disk survived, host replaced): bring the replacement up with the same broker id and log directory. It rejoins, catches up from the leaders, and no reassignment is needed. This is the cheapest path and the reason broker ids and storage should be stable in your deployment.

New broker id, or data lost: the partitions that lived on the old broker must be moved.

 1. Add the new broker to the cluster; confirm it is live
 2. Generate a reassignment plan moving the dead broker's replicas
      kafka-reassign-partitions.sh --generate
 3. Execute it WITH A THROTTLE
      kafka-reassign-partitions.sh --execute --throttle <bytes/sec>
 4. Verify until complete
      kafka-reassign-partitions.sh --verify        (also removes the throttle)
 5. Rebalance leadership so the new broker takes its share
 6. Only now decommission the old broker id

The throttle is the part people skip and regret. Unthrottled reassignment moves data as fast as the disks and network allow, which starves live produce and fetch traffic — you turn a degraded cluster into a slow one. Move partitions in batches rather than the whole cluster at once, and watch produce latency while it runs.

Two related cautions: reassignment is the same tool used for "rebalancing storage", so the same throttling discipline applies; and moving a large partition means copying its entire retained history, so plan the window using the storage arithmetic from earlier in this module.

Practising failure

The uncomfortable truth is that the runbook you have not rehearsed is fiction. Three drills, in order of value:

  1. Kill one broker in a non-production cluster and watch leader election, client retries, and under-replicated partition recovery. Confirm producers with acks=all survive it.
  2. Force a rebalance storm by setting a low max.poll.interval.ms and observe the signature, so you recognise it later.
  3. Feed a poison message to a consumer and confirm your dead-letter path works before it is needed.

Exercise: At 02:00 a service's lag begins climbing on all 12 partitions of one group. UnderReplicatedPartitions is 0, no deploy occurred, producer throughput is unchanged, and a nightly analytics backfill started at 01:55 reading the same topic from the beginning. Rank the three most likely causes, state the one metric that would distinguish them fastest, and give the action you would take that does not require changing the consumer application.