title: Kafka DefaultPartitioner algorithm
body: <p>There is a very small but very powerful detail in the Kafka <code>org.apache.kafka.clients.producer.internals.DefaultPartitioner</code> implementation that bugs me a lot.</p>
  
  <p>It is this line of code:</p>
  
  <pre><code>return DefaultPartitioner.toPositive(Utils.murmur2(keyBytes)) % numPartitions;
  </code></pre>
  
  <p>to be more precise, the last <code>% numPartitions</code>. I keep asking myself what is the reason behind introducing such a huge constraint by making the partition ID a function of the number of existent partitions? Just for the convenience of having small numbers (human readable/traceable?!) in comparison to the total number of partitions? Does anyone here have a broader insight into the issue?</p>
  
  <p>I'm asking this because in our implementation, the key we use to store data in kafka is domain-sensitive and we use it to retrieve information from kafka based on that. For instance, we have consumers that need to subscribe ONLY to partitions that present interest to them and the way we do that link is by using such keys.</p>
  
  <p>Would be safe to use a custom partitioner that doesn't do that modulo operation? Should we notice any performance degradation. Does this have any implications on the Producer and/or Consumer side?</p>
  
  <p>Any ideas and comments are welcome.</p>