liveBook · Manning

Partitioning key

As explained in Akka in Action, Second Edition

A partition key is a value used to deterministically assign an entity or actor to a distribution partition.

A partitioning key is a stable value that keeps related work together while distributing independent work. In consistent-hashing routing, a message is mapped to a String message key; messages that must be joined, such as those sharing an ID, must always produce the same key. The router hashes that key, selects a virtual node, and sends the message to the routee responsible for it. section 6.3.4

Figure 6.7 Steps the consistent hashing router follows to decide which routee to select
CH06_F07_Abraham2

The routing path makes the key’s role explicit: message key, hash code, virtual node, then routee. Virtual nodes improve the chance of even distribution and accommodate routee additions or removals. section 6.3.4

Choose and apply a key with these constraints:

  • Derive it from the identity that defines related messages, such as a message ID, rather than from changing message content. section 6.3.4
  • Implement a mapping function for each message type; consistent hashing requires the message-to-key mapping explicitly. section 6.3.4
  • Configure the virtual-node factor for the router, because each routee serves a configured number of virtual nodes. section 6.3.4

Route aggregation by message ID

An obfuscator and an enricher can each route output to an aggregator using the same message ID as the key. Similar messages then reach the same routee and aggregator, so their pieces can be combined correctly. A group router uses the aggregator ServiceKey together with the consistent-hashing mapping. section 6.3.4

Partitioning also appears at the cluster level. Cluster sharding automatically distributes actors across nodes using a partition key, and uses that same key to communicate with those actors. This combines placement, load balancing, and resilience when nodes leave the cluster. section 8.1

How Akka in Action, Second Edition covers it

How deep it goes
Explains key extraction, hashing, virtual-node selection, and routee assignment; defers cluster sharding details.
Examples
Uses an obfuscator, enricher, and aggregator that share message IDs to join related outputs.
What it assumes
Introduces the key mapping within an Akka router scenario without requiring prior failure-handling experience.
What you can do after
Apply it via Akka routers by implementing a stable message-to-key mapping and configuring consistent hashing.
How it connects
Connects consistent hashing with routers, virtual nodes, ServiceKey, cluster sharding, and load balancing.

Also explained in

Compare how 10 books explain partitioning key →

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.