Introduction

Consistent hashing is a special kind of hashing such that when a hash table is resized, only K/N keys need to be remapped on average, where K is the number of keys, and N is the number of slots. This article gives a good explanation about it.

Property

Monotonicity

Balance

Usage

Distributed Caching System

Load Balance

Code Practice

As a practice, I design a cache system to store person information in a few cache servers using consistent hashing.

And then remove one server from the cache system to observe affected data, it shows that only data on this removed server are affected. And we don’t need to remap other data stored on other servers.

Next

Above solution is naive. Normally, when a server was failure, we can map data on that server to other servers. Also, if we could add new servers to the ring, we need to split data from others to this new added server.