Technical Overview of Akka.Cluster.Sharding in Akka.NET
How Akka.Cluster.Sharding Allocates Shards, Rebalances, and More
In our previous post about using Akka.Cluster.Sharding we looked at the module from an end-user’s perspective. Today we’ll provide a little more insights into how this plugin works internally.
Cluster sharding depends on several types of actors:
- Coordinator - one per entity type for an entire cluster.
- Shard region - one per entity type per each cluster node, where sharding should be enabled.
- Shard - there can be many on each shard region, and they can move between shard regions located on different nodes.
- Entity - actors defined by the end-user. There can be many on each shard, but they are always bound to a specific shard.
All of them can be visualized using diagram below:
If you look at actor paths of the entities you’ve created you’ll see that they reflect the structure of that hierarchy. They follow the pattern /user/sharding/<typeName>/<shardId>/<entityId>
. Given that, it’s easy to infer that /user/sharding/<typeName>
is path to a shard region while subsequent path segments are responsible for shard actor and entity actor.