Discuss strategies for Kafka's data rebalancing during scaling operations.
Instruction: Explain how Kafka handles data rebalancing when brokers are added or removed and the challenges associated with it.
Updated
Official answer
Separate three operations: replica reassignment between brokers, partition leadership balancing, and consumer-group assignment. Range/RoundRobin/cooperative consumer assignors do not move stored partition replicas to newly added brokers.
In a standard self-managed Kafka cluster, merely adding a broker does not automatically redistribute existing topic data across it. Plan replica reassignment using the administrative tools or a separately configured balancing system. Review partition sizes, traffic, disk headroom and rack placement rather than balancing only the number of partitions.
Generate or author a candidate reassignment, retain the current assignment for recovery planning, and review that replication factor and failure-domain placement remain valid. Execute a bounded set of moves with an appropriate replication throttle. A throttle below the incoming write rate may prevent replicas from catching up, so monitor progress as well as foreground latency.
Wait for the new replicas to catch up and verify completion and ISR health. Remove temporary throttles when they are no longer required, and check leader distribution separately. Before decommissioning a broker, move all relevant replicas off it and verify that no required partition depends on it; shutting it down first is not a safe migration plan.
Consumer groups may experience effects from leadership changes or other concurrent events, but session timeouts and consumer assignors are not the primary tools for broker data placement. Measure migration bytes/lag, disk/network saturation, under-replicated partitions and application latency. Pause or adjust the plan if safety or service targets degrade; do not promise disruption-free movement under every load.
Source
Kafka operations: cluster expansion, reassignment and throttling.