Learn Labs
Operations

Cluster Operations

Reassigning partitions, adding brokers, changing configs, and upgrading

Day-to-day Kafka operations are mostly about moving data safely: when a broker is added, removed, or overloaded, partitions have to move, and moving partitions means copying data across the network. The book's Administering Kafka chapter covers the admin APIs; here's the workflow.

Partition reassignment

kafka-reassign-partitions.sh moves replicas between brokers in three steps: generate a plan, execute it, verify it.

Run on this cluster with a topic whose replicas were only on brokers 1 and 2:

kafka-topics.sh $B --create --topic events --replica-assignment 1:2,1:2,2:1
Partition: 0  Leader: 1  Replicas: 1,2
Partition: 1  Leader: 1  Replicas: 1,2
Partition: 2  Leader: 2  Replicas: 2,1

# 1. generate: spread it across all three brokers
echo '{"topics":[{"topic":"events"}],"version":1}' > /tmp/t.json
kafka-reassign-partitions.sh $B --topics-to-move-json-file /tmp/t.json \
--broker-list 1,2,3 --generate | tail -1 > /tmp/plan.json

# 2. execute, with a replication throttle so the copy can't swamp the network
kafka-reassign-partitions.sh $B --reassignment-json-file /tmp/plan.json --execute --throttle 50000000
The inter-broker throttle limit was set to 50000000 B/s
Successfully started partition reassignments for events-0,events-1,events-2

# 3. verify: reports progress, and removes the throttles once everything is done
kafka-reassign-partitions.sh $B --reassignment-json-file /tmp/plan.json --verify
Reassignment of partition events-2 is completed.
Clearing broker-level throttles on brokers 1,2,3
Clearing topic-level throttles on topic events

Partition: 0  Leader: 1  Replicas: 3,1  Isr: 1,3
Partition: 1  Leader: 1  Replicas: 1,2  Isr: 1,2
Partition: 2  Leader: 2  Replicas: 2,3  Isr: 2,3

During a reassignment, the new replica fetches the whole partition from the leader, joins the ISR, and only then is the old replica removed. The partition is never under-replicated by design.

After the move, partition 0's preferred leader is 3 but its leader is still 1. Finish with a preferred leader election.

Adding a broker

A new broker gets no data automatically: existing partitions stay where they are, and only new topics use it. To use it:

  1. Start it with a new node.id and the same CLUSTER_ID.
  2. Reassign some partitions onto it (generate with a broker list that includes it).
  3. Run a preferred leader election.

Tools like Cruise Control automate the "which partitions should move" decision based on load.

Removing a broker

The reverse: reassign everything off it, verify, then shut it down. In KRaft, also unregister it: kafka-cluster.sh unregister --bootstrap-server ... --id 4.

Changing configuration

Many settings are dynamic, changeable at runtime without a restart:

kafka-configs.sh $B --alter --entity-type topics --entity-name demo --add-config retention.ms=86400000kafka-configs.sh $B --alter --entity-type brokers --entity-default --add-config log.cleaner.threads=2kafka-configs.sh $B --alter --entity-type brokers --entity-name 1 --add-config num.io.threads=16kafka-configs.sh $B --describe --entity-type brokers --entity-name 1 --all | grep -i dynamic

Others (listeners, process.roles, log.dirs) need a rolling restart, one broker at a time, waiting for zero under-replicated partitions between each (see Broker Failures).

Upgrades

Kafka upgrades are rolling restarts with one extra step:

  1. Read the upgrade notes for every version you're crossing.
  2. Upgrade brokers (and controllers) one at a time to the new binary.
  3. Once every node runs the new version and the cluster is stable, bump the feature level: kafka-features.sh --bootstrap-server ... upgrade --metadata 4.3.
  4. Clients can be upgraded independently; brokers support old protocol versions.

Until step 3, the cluster keeps the old metadata format, so you can still roll back the binaries. After it, you can't. That's the whole reason it's a separate, deliberate step.

Lab

  1. Reproduce the events reassignment above, then run the preferred election and describe the topic.
  2. Run the same reassignment without --throttle on a topic with 50 MB of data, and compare how long it takes.
  3. Change retention.ms on a topic dynamically and confirm with --describe.
  4. Read kafka-features.sh describe, and find where the current metadata.version is shown.

On this page