liveBook · Manning

Consistent hashing

As explained in Elixir in Action, Third Edition

Consistent hashing is a key-to-node mapping technique that limits remapping when nodes are added to or removed from a distributed system.

Consistent hashing maps keys to nodes while limiting remapping when cluster membership changes. It reduces the data migration required when nodes join or leave a distributed cache. section 12.2.2

Use it when a simple mapping becomes difficult to operate:

  • Adding or losing a node changes ordinary mapping rules and can redirect many keys. section 12.2.2
  • Migrating redirected data while keeping the service running adds operational complexity. section 12.2.2
  • Prefer the simpler mapping first when scalability requirements do not justify the added implementation complexity. section 12.2.2

Simple mapping before consistent hashing

A cache can sort visible nodes, hash a to-do list name with :erlang.phash2, select a node, and call Todo.Cache.server_process remotely. This illustrates the mapping problem that consistent hashing improves.

How Elixir in Action, Third Edition covers it

How deep it goes
Defines the operational benefit but stops short of implementing the hashing algorithm or migration procedure.
Examples
Uses a to-do cache that hashes list names onto sorted visible nodes before issuing a remote cache call.
What it assumes
Assumes familiarity with distributed caches, cluster nodes, process discovery, and data migration.
What you can do after
Evaluate when a simple key-to-node mapping should give way to a more scalable, change-resistant approach.
How it connects
Connects distributed caches with cluster membership, data migration, node discovery, and remote procedure calls.

Also explained in

Compare how 2 books explain consistent hashing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.