javadhtconsistent-hashing

How does consistent hashing work?


I am trying to understand how consistent hashing works. This is the article which I am trying to follow but not able to follow, to start with my questions are:

  1. I understand, servers are mapped into ranges of hashcodes and the data distribution is more fixed and look becomes easy. But how does this deal with the problem a new node is added in the cluster?

  2. The sample java code is not working, any suggestion of a simple java based consistent hashing.

Update

  1. Any alternatives to consistent hashing?

Solution

  • I will answer the first part of your question. First of all, there are some errors in that code, so I would look for a better example.

    Using a cache server as the example here.

    When you think about consistent hashing, you should think of it as a circular ring, as the article you linked to does. When a new server is added, it will have no data on it to start with. When a client fetches data that should be on that server and does not find it, a cache-miss will occurs. The program should then fill in the data on the new node, so future requests will be a cache-hit. And that is about it, from a caching point of view.