Search code examples
akkaakka.netakka-cluster

What is the difference between these two cluster configurations?


I see that there's a setting called "roles" you can specify in Akka.Cluster configuration. If I understand it right, entities/actors with only run on nodes where the entity role and the nodes "roles" configuration setting matches.

I also see another configuration setting called "role" in Akka.Cluster.Sharding. What is the difference between this and the above setting?


Solution

  • Roles are sort of labels you tag each actor system with, nothing fancy.

    You can implement different behaviours/logic depending on the roles of the actor system your code is running in by checking Cluster(system).selfRoles.

    Akka cluster sharding and cluster singleton use this to limit the deployment of a shard/singleton to a set of actor systems tagged with a specific role.

    To sum up both roles your mention are different sides of the same coin. akka.cluster.roles are tags for the actor system and the role setting in akka.cluster.sharding instructs to start the shard only on nodes tagged with that role.