You are on page 1of 1

Keys distribution model

The key space is split into 16384 slots, effectively setting an upper limit for the cluster
size of 16384 master nodes (however the suggested max size of nodes is in the order
of ~ 1000 nodes).
Each master node in a cluster handles a subset of the 16384 hash slots. The cluster
is stable when there is no cluster reconfiguration in progress (i.e. where hash slots are
being moved from one node to another). When the cluster is stable, a single hash slot
will be served by a single node (however the serving node can have one or more slaves
that will replace it in the case of net splits or failures, and that can be used in order to
scale read operations where reading stale data is acceptable).
The base algorithm used to map keys to hash slots is the following (read the next
paragraph for the hash tag exception to this rule):

HASH_SLOT = CRC16(key) mod 16384

The CRC16 is specified as follows:

• Name: XMODEM (also known as ZMODEM or CRC-16/ACORN)


• Width: 16 bit
• Poly: 1021 (That is actually x16 + x12 + x5 + 1)
• Initialization: 0000
• Reflect Input byte: False
• Reflect Output CRC: False
• Xor constant to output CRC: 0000
• Output for "123456789": 31C3

14 out of 16 CRC16 output bits are used (this is why there is a modulo 16384 operation
in the formula above).
In our tests CRC16 behaved remarkably well in distributing different kinds of keys
evenly across the 16384 slots.
Note: A reference implementation of the CRC16 algorithm used is available in the
Appendix A of this document.

Keys hash tags


There is an exception for the computation of the hash slot that is used in order to
implement hash tags. Hash tags are a way to ensure that multiple keys are allocated in
the same hash slot. This is used in order to implement multi-key operations in Redis
Cluster.
In order to implement hash tags, the hash slot for a key is computed in a slightly
different way in certain conditions. If the key contains a "{...}" pattern only the substring
between { and } is hashed in order to obtain the hash slot. However since it is possible

You might also like