Understanding Consistent Hashing

Posted on by Tom

Introduction

Consistent hashing is a distributed hashing scheme that operates independently of the number of servers or objects in a distributed hash table.

The Problem

In traditional hash tables, when the number of slots changes, most keys need to be remapped. This is particularly problematic in distributed systems where nodes can come and go frequently.

How Consistent Hashing Works

Consistent hashing maps both servers and keys to the same space...

Implementation Example


fun createHashRing(nodes: List): SortedMap {
    val hashRing = sortedMapOf()
    nodes.forEach { node ->
        val hash = node.hashCode()
        hashRing[hash] = node
    }
    return hashRing
}
            

Applications

Further Reading