educative.io

Educative

How consistent hashing solve the hot key issue?

Let’s taking the “State” example from the lesson, what if most of the records are for “CA”, then even with consistent hashing(and virtual nodes) the most records would be on one node.


Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5559029852536832
Lesson: https://www.educative.io/collection/page/5668639101419520/5559029852536832/6501426287607808

Hey @Kangkai_Tang!

This actually won’t be the case. The reason being that in the case of virtual nodes, instead of having a single hashing function, we now use multiple hash functions for hashing which, as mentioned in the lesson, divides the hash range into multiple smaller ranges. With this, the load will be more evenly placed now instead of crowding on a single node.

If we take the example of “CA”, its key will first be hashed using the first hash function followed by the second and then the third. Very rarely would two keys collide with one another.

hash3(hash2(hash(CA))) != hash3(hash2(hash(CA))) ? how could this happen?

1 Like