What if your messages got lost or jumbled because they weren't sorted right?
Why Partitioner behavior in Kafka? - Purpose & Use Cases
Imagine you have a huge box of letters to send to different cities, and you try to sort them by hand into piles for each city before mailing.
Sorting each letter manually is slow and mistakes happen easily, like putting letters in the wrong pile or missing some. This causes delays and lost mail.
A partitioner automatically decides which pile (partition) each letter (message) belongs to, based on rules like the city name. This makes sorting fast, accurate, and consistent.
send(message) // no control over where message goes
send(message, key) // partitioner uses key to pick partition
It lets Kafka distribute messages evenly and predictably across partitions, improving speed and reliability.
In an online store, orders from the same customer always go to the same partition, so their order history stays in order and is easy to find.
Manual message routing is slow and error-prone.
Partitioners automate and speed up message distribution.
Consistent partitioning keeps related data together for easy processing.