# Why can the first 12 bits of key's digest be the partition id?

**URL:** https://discuss.aerospike.com/t/why-can-the-first-12-bits-of-keys-digest-be-the-partition-id/1616
**Category:** General Discussion
**Created:** [August 12, 2015, 9:34am UTC](https://discuss.aerospike.com/t/why-can-the-first-12-bits-of-keys-digest-be-the-partition-id/1616 "2015-08-12T09:34:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kai\_Guo](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@Kai\_Guo](https://discuss.aerospike.com/u/Kai_Guo)
#### Post date: [August 12, 2015, 9:34am UTC](https://discuss.aerospike.com/t/why-can-the-first-12-bits-of-keys-digest-be-the-partition-id/1616/1 "2015-08-12T09:34:03Z")

</div>

As we know, the key is hashed to a fixed 20 bytes string with RIPEMD160. Then choose the first 12 bits of the string(key’s digest) as partition id. I want to figure out that how the hash algorithm RIPEMD160 ensure the keys are evenly distributed on all 4096 partitions. Because partitions are evenly distributed on the cluster nodes.

---

<div class="post-metadata">

### Author: ![raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@raj](https://discuss.aerospike.com/u/raj)
#### Post date: [August 12, 2015, 1:15pm UTC](https://discuss.aerospike.com/t/why-can-the-first-12-bits-of-keys-digest-be-the-partition-id/1616/2 "2015-08-12T13:15:01Z")

</div>

Kai\_Guo,

RIPEMD160 hash generates fairly random bits based on the key. Randomness ensures even distribution.

Any set of bits can be picked to determine the partition ID. We just happen to pick first 12 bits.

HTH

– R

---

<div class="post-metadata">

### Author: ![Kai\_Guo](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@Kai\_Guo](https://discuss.aerospike.com/u/Kai_Guo)
#### Post date: [August 12, 2015, 2:02pm UTC](https://discuss.aerospike.com/t/why-can-the-first-12-bits-of-keys-digest-be-the-partition-id/1616/3 "2015-08-12T14:02:37Z")

</div>

raj,

> [@raj](#):
>
> RIPEMD160 hash generates fairly random bits based on the key

So it is RIPEMD160‘s characteristic that decides a large number of keys will be evenly distributed on 4096 partition. For example, there are 4096000 keys, so every partition has nearly 1000 keys. Is it correct?

Another question is as follows. In server code, I notice there is a phase called ‘Partition Map’. You guys implemented this using FNV-1a hash and One-at-a-Time hash. After partition map, it seems that partitions are also evenly disteibuted on all cluster nodes. So it is these two hash functions that decide it?

I will appreciate for your patience answers.🙂

---

<div class="post-metadata">

### Author: ![raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@raj](https://discuss.aerospike.com/u/raj)
#### Post date: [August 12, 2015, 3:34pm UTC](https://discuss.aerospike.com/t/why-can-the-first-12-bits-of-keys-digest-be-the-partition-id/1616/4 "2015-08-12T15:34:16Z")

</div>

That is right !!

– R

---

<div class="post-metadata">

### Author: ![Kai\_Guo](https://avatars.discourse-cdn.com/v4/letter/k/df788c/32.png) [@Kai\_Guo](https://discuss.aerospike.com/u/Kai_Guo)
#### Post date: [August 13, 2015, 12:27am UTC](https://discuss.aerospike.com/t/why-can-the-first-12-bits-of-keys-digest-be-the-partition-id/1616/5 "2015-08-13T00:27:12Z")

</div>

I wonder how you find these three hash functions to solve distributed problem. but actually they work.
