Skip to content
Exercise · Kafka producers · lesson 2 of 8

Exercise: the keyed partitioner

In Kafka, records with the same key land in the same partition, so a consumer reads them in the order they were sent. The partition is chosen by the producer, not the broker: Kafka's Java client and franz-go compute the murmur2 hash of the key's bytes and take the remainder of dividing it by the number of partitions. This exercise needs no broker: you repeat the Kafka client's code.