What is Kafka rebalancing? When does rebalancing occur in Kafka?

Each consumer belonging to a consumer group is assigned certain partitions of a topic in order to consume messages from the topic. Rebalancing refers to the redistribution of the partitions of a topic across the consumers of a group. This typically occurs when a new consumer joins a group or when a consumer from a group stops working. In such scenarios, partitions are rebalanced across all the available consumers.