Broker Failures
Killing brokers under load, under-replicated partitions, and losing the quorum
This lesson is a guided failure drill. Run it with the Kafka Overview
Grafana dashboard open (start ../prometheus first) and lag.py
running, so there's real traffic flowing.
# terminal 1: steady traffic and a consumer group
docker compose -f compose_prod.yaml run --rm labs python lag.py
# terminal 2: watch partition state
watch -n 2 'docker exec kafka-1 /opt/kafka/bin/kafka-topics.sh \
--bootstrap-server localhost:19092 --describe --topic clicks'Drill 1: one broker dies
docker stop kafka-3What you should see, and why:
- Partitions led by broker 3 get a new leader within seconds (from the ISR).
- Every partition with a replica on broker 3 is under-replicated:
ISR of 2.
kafka-topics.sh --describe --under-replicated-partitionslists them. In this lab that was 202 partition lines, because internal topics count too. - Producers with
acks=allkeep working: ISR 2 ≥min.insync.replicas2. - Consumers whose group coordinator was on broker 3 pause briefly while the coordinator moves; lag spikes, then recovers.
- On the dashboard: Brokers up 2, Under-replicated partitions > 0, and
the
KafkaUnderReplicatedPartitionsalert goes pending.
docker start kafka-3
# it rejoins, fetches everything it missed, and re-enters the ISRDrill 2: two brokers die
docker stop kafka-2 kafka-3- ISR shrinks to 1 for every partition.
acks=allproducers fail withNOT_ENOUGH_REPLICAS. The cluster refuses writes rather than accept data held by one disk.acks=1producers still succeed, and those writes are at risk.- The KRaft quorum is lost: only 1 of 3 controllers is up. Existing
leaders keep serving, but nothing can change. In this lab
kafka-metadata-quorum.sh describe --statusjust hung. No leader election could happen if broker 1 failed now.
This is the strongest argument for dedicated controllers in production. With combined nodes (as in this lab), losing two brokers also loses the metadata quorum. With three dedicated controllers on separate machines, you can lose two brokers and the cluster can still elect leaders and change configuration.
Drill 3: a broker comes back after a long outage
Stop a broker for longer, keep producing, then start it. It must fetch
everything it missed before rejoining the ISR. On a real cluster with
terabytes per broker, that catch-up can take hours and saturate the
network, which is why replica.fetch.max.bytes, replication quotas, and
"don't restart all brokers at once" matter.
kafka-configs.sh --bootstrap-server localhost:19092 --alter --entity-type brokers --entity-default \
--add-config leader.replication.throttled.rate=50000000,follower.replication.throttled.rate=50000000
# the rates only apply to replicas listed as throttled on each topic ("*" = all of them)
kafka-configs.sh --bootstrap-server localhost:19092 --alter --entity-type topics --entity-name clicks --add-config leader.replication.throttled.replicas=*,follower.replication.throttled.replicas=*Remove both settings once the broker has caught up, or replication stays throttled forever.
Drill 4: rolling restart
The safe way to restart every broker (config change, upgrade):
- Restart one broker.
- Wait until
--under-replicated-partitionsis empty. - Run a preferred leader election if leadership drifted.
- Move to the next broker.
Restarting the next broker while partitions are still under-replicated
can push them below min.insync.replicas and stop writes.
What you've learned from the drills
| Failure | Writes (acks=all) | Reads | Data loss |
|---|---|---|---|
| 1 of 3 brokers | Continue | Continue | None |
| 2 of 3 brokers | Refused | Continue from remaining leaders | None |
2 of 3 with acks=1 | Continue | Continue | Possible on the next failure |
| 2 of 3 with unclean election | Continue after unclean election | Continue | Yes |
Lab
Run all four drills. For each, write down: what alerted, what the
dashboard showed, and what the producer and consumer in lag.py logged.
That table is a good start for a runbook.