12 Comments

Great article, it helped me to learn alot

Expand full comment

Thank you for this article.

Learned new things.

Expand full comment

With virtual node distribution can you share ring structure as well. This would be become more easy . Thank you for this article. One of the core concept in scaling of systems

Expand full comment

yeah.. good point. I will add the ring structure with virtual node distribution.

Expand full comment

Your writing is incredible, super concise but easy to understand, thanks for this! 🙌

Expand full comment

Great to hear this, thank you 😊

Expand full comment

Shouldn’t you be redistributing when you remove and add a node in the Python implementation?

Expand full comment

Explicitly redistributing isn’t required since inserting and removing hash values of servers in the sorted_keys data structure automatically takes care of it. Since sorted_keys is sorted by hash values, while adding and removing the order of other server hash values doesn't change.

Expand full comment

Got it, Thanks for answering so quickly

Expand full comment

The article is really incredible, very helpful to understand the consistent hashing for a beginner like me.

I was wondering If it’s possible to have an edge case like 2 different virtual nodes sharing the same hash code(collision). If so how do we handle the remove servers when 2 virtual happen to share the same hash code.

Expand full comment

Great observation! While hash collisions are rare, they can still happen. In this implementation, the sorted_keys structure may store the same hash value for different virtual nodes. Currently, collisions aren’t explicitly handled, but they can be resolved by storing pairs {hash_value, virtual_node_id} instead of just hash values. This way, when removing a server, we can accurately identify and delete the correct virtual node, even if multiple nodes share the same hash.

Expand full comment

Thanks for the quick reply

Expand full comment