Messages are sent to various partitions associated with a topic in a round-robin fashion.
If there is a requirement to send a message to a particular partition, then it is possible to associate a key with the message.
The key determines which partition that particular message will go to.
All messages with the same key will go to the same partition.
If a key is not specified for a message, the producer will choose the partition in a round-robin fashion.
https://medium.com/event-driven-utopia/understanding-kafka-topic-partitions-ae40f80552e8