Distributing State Evenly and Automatically with Self-Managing Actors
In this post, we’ll discuss one of the Akka.NET plugins, Akka.Cluster.Sharding and how it gives us easier, higher level abstractions to work with actors (in this case also referred to as entities). Cluster.Sharding gives us:
- By using a logical keys (in form of ShardId/EntityId pairs) it’s able to route our messages to the right entity without need to explicitly determine on which node in the cluster it lives.
- It automatically manages the process of actor creation, so you don’t have to do it explicitly. When a message is addressed to an entity that didn’t exist, an actor for that entity will be created automatically.
- It’s able to rebalance actors across cluster as it grows or shrinks, to ensure its optimal usage.
Given all of those traits, let’s see how to utilize cluster sharding in a standard Akka.NET application.