Tuesday, August 11, 2020

System design: Consistent hashing

 Here is the article. 

It is interesting to learn how to explain consistent hashing in his writing. I may like to add some review on his writing as well. 


From the article. 

Consistent hashing, and was first described by Karger et al. at MIT in an academic paper from 1997 (according to Wikipedia).

Consistent Hashing is a distributed hashing scheme that operates independently of the number of servers or objects in a distributed hash table by assigning them a position on an abstract circle, or hash ring. This allows servers and objects to scale without affecting the overall system.

Distributed hash key value:

To ensure object keys are evenly distributed among servers, we need to apply a simple trick: To assign not one, but many labels (angles) to each server. So instead of having labels AB and C, we could have, say, A0 .. A9B0 .. B9 and C0 .. C9, all interspersed along the circle. The factor by which to increase the number of labels (server keys), known as weight, depends on the situation (and may even be different for each server) to adjust the probability of keys ending up on each. For example, if server B were twice as powerful as the rest, it could be assigned twice as many labels, and as a result, it would end up holding twice as many objects (on average).

Removing a server results in its object keys being randomly reassigned to the rest of the servers, leaving all other keys untouched:

Example:

Can you explain how you got 58.8

KEY HASH ANGLE (DEG)
"john" 1633428562 58.8
"bill" 7594634739 273.4
"jane" 5000799124 180
"steve" 9787173343 352.3
"kate" 3421657995 123.2
"A" 5572014558 200.6
"B" 8077113362 290.8
"C" 2269549488 81.7


What I understood was, you take the ratio of the key with the max num, and multiply it by 360(total angle in the circle).
So, max in our case is 10^10(he mentioned it).
So, for John, angle = (1633428562 / 10^10) * 360 = 58.8


Exactly. Just keep in mind we don't really need angles in the actual implementation (the circle is just a way to visualize it).


No comments:

Post a Comment