liveBook · Manning

Consistent hashing

As explained in Akka in Action, Second Edition

Consistent hashing is a hashing algorithm that assigns keys to a changing set of nodes while minimizing key reassignment when nodes are added or removed.

Consistent hashing assigns related messages to the same routee, preserving message affinity as routees join or leave. In a worker pipeline, it lets obfuscation and enrichment results reach the same aggregator instead of being merged incorrectly. section 6.3.4

A consistent-hashing router follows this path:

  • Convert each message into a string key. section 6.3.4
  • Hash the key and use the result to select a routee deterministically. section 6.3.4 section 6.5
  • Use the same mapping for corresponding worker outputs, so the aggregator receives both pieces of one original message. section 6.3.4

Routing enrichment results to the matching aggregator

Define the aggregator key as the message id, then configure a group router with consistent hashing: Routers.group(Aggregator.serviceKey).withConsistentHashingRouting(10, Aggregator.mapping). The enricher sends Aggregator.Enriched(id, content + ":metadata"), allowing matching results to reach the same aggregator.

How Akka in Action, Second Edition covers it

How deep it goes
Explains deterministic key-based routing and shows Akka configuration, while treating detailed router steps as internal.
Examples
Uses obfuscation, enrichment, aggregation, message identifiers, and an Akka group-router configuration.
What you can do after
Apply it via an Akka group router by defining a message-key mapping and consistent-hashing routee strategy.
How it connects
Connects hashing with data partitioning, group routers, routee discovery, aggregators, and message routing.

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 Akka in Action, Second Edition. The section links point to the parts of the book it draws on.