Learn Labs
Replication & Failure

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-3

What 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-partitions lists them. In this lab that was 202 partition lines, because internal topics count too.
  • Producers with acks=all keep working: ISR 2 ≥ min.insync.replicas 2.
  • 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 KafkaUnderReplicatedPartitions alert goes pending.
docker start kafka-3
# it rejoins, fetches everything it missed, and re-enters the ISR

Drill 2: two brokers die

docker stop kafka-2 kafka-3
  • ISR shrinks to 1 for every partition.
  • acks=all producers fail with NOT_ENOUGH_REPLICAS. The cluster refuses writes rather than accept data held by one disk.
  • acks=1 producers 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 --status just hung. No leader election could happen if broker 1 failed now.

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):

  1. Restart one broker.
  2. Wait until --under-replicated-partitions is empty.
  3. Run a preferred leader election if leadership drifted.
  4. 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

FailureWrites (acks=all)ReadsData loss
1 of 3 brokersContinueContinueNone
2 of 3 brokersRefusedContinue from remaining leadersNone
2 of 3 with acks=1ContinueContinuePossible on the next failure
2 of 3 with unclean electionContinue after unclean electionContinueYes

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.

On this page