Can we create akka actor from the context of shard actor?

31 Views Asked by At

I want to understand can we create an actor from the context of shard actor(from inside shard actor) and delegate some work to it? If i create an actor from shard actor ,are there any limitations ? What are the PROS and CONS of doing this?

1

There are 1 best solutions below

0
On

It is possible to spawn child actors of a sharded actor. However, it's important to remember that a sharded actor can and will be stopped by sharding in order to move the shard to another node. Depending on when in the lifecycle of the sharded actor the child actors are spawned, this may necessitate persisting that there should be a child actor running: if the child is spawned as part of the sharded actor starting, this persisting isn't necessary, but if the child is spawned in response to a message, it likely will have to be persisted (whatever sent that message likely views sharded actors for a given entity ID to be "incarnations" of that entity's "eternal soul").

Another thing to be aware of is that cluster sharding requires its actors to be able to shut themselves down in a bounded amount of time: if an actor spawns children, this time includes the time to shut down the children, otherwise a more forceful, less orderly, and less likely to be "clean" shutdown will be performed. It's therefore extra critical to ensure that the child actors don't become unresponsive.