title: Kafka: Is it possible for the same Key(string) to resolve to multiple partition in Kafka?
body: <p>We read the incoming records from our application and use user ID (as string) as Key for producer record when creating producer record in Kafka. There are thousands of user Id that the application handles per day.</p>
  
  <p>What we noticed was the records having the same key (Z132384910042467345-0) were sent to the same partition (partition 2) most of the times but sometimes getting sent to partition 1 and 0. Is this possible in Kafka given that we do not use a CustomPartitioner ? I looked at the source code and they do hashing of key % partition count to arrive at the partition but can't figure out why the same key is mapped to different partitions. </p>
  
  <p>P.S: Also looked at the source data (containing user IDs) for any anomaly but could not find anything. </p>
  
  <pre><code>if (partitionKey != null &amp;&amp; partitionKey.length() &gt; 0){
          kafkaProps = kafkaConfigService.getProps(kafkaConfigService.getKafkaMode());
          record = new ProducerRecord(topicName, partitionKey, data);
      } else {
          LOG.error("partitionKey is null. Choosing a random partition");
          kafkaProps = kafkaConfigService.getProps(kafkaConfigService.getKafkaMode());
          record = new ProducerRecord(topicName, data);
      }
  </code></pre>