BeginnerCore Concepts
What is a Kafka producer and how does key-based partitioning work?
Reference answer
A Kafka producer is a client that publishes messages to topics. When a message has a key, Kafka uses murmur2 hash of the key modulo the partition count to consistently route messages with the same key to the same partition. This guarantees ordering for all messages with the same key. Without a key, messages are distributed using round-robin or sticky partitioner (Kafka 2.4+) for balanced load. Key-based partitioning is essential for maintaining event ordering per entity (e.g., all orders from one customer).
Expected key concepts: producer, key, murmur2, hash, consistent routing, same partition, ordering, round-robin, sticky partitioner