While reading Alex Xu's book on designing large systems, I had a question about the part about consistent hashing.
The book says that in a stable hash, the server where the key will be stored is a linear search in a clockwise direction, looking for the first server it encounters.
If so, I'm wondering if there is a time complexity penalty for searching than the hashing method using modulo. (modulo means. general hashing)
Let's look at this diagram which depicts how the consistent hashing based lookup works.
The hash ring
s4)Lookup
In the above example we wanted to place
key0on to theserver 0. But due to a server failure it has been removed the cluster. A new serverserver 4has been added to cluster to replaceserver 0. Becauses4has been placed betweens3ands1nodes that's why that's the closest server node clockwise to thek0hash.Time complexity
To better understand consistent hashing I highly recommend to you to read this excellent article: http://highscalability.com/blog/2023/2/22/consistent-hashing-algorithm.html
Please allow me to quote here the time complexity table for binary-search-tree
O(k/n + logn)O(k/n)for redistribution of keysO(logn)for binary search tree traversalO(k/n + logn)O(k/n)for redistribution of keysO(logn)for binary search tree traversalO(logn)O(logn)for binary search tree traversalO(logn)O(logn)for binary search tree traversalwhere
k= total number of keys,n= total number of nodes [2, 7].