Can we create actor from the context of shard actor?

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?
What are the PROS and CONS of doing this?

Yes, the sharded actors are regular actors so can do whatever a regular actor can. One aspect that is a bit tricky that doesn’t happen to normally spawn actors is that the sharded actors may be rebalanced, to be more evenly spread across the cluster.

Normally this means stopped and then restarted on a new cluster node once the next message for it arrives, with remember-entities enabled it will be auto-restarted on the new node without receiving any new messages.

If the actor had started child actors, it will likely need persist the fact that it started children and whatever initial parameters passed to start those, and re-start them when it starts on a new node, to continue work from the state where it left off when stopped.

Okay ,Thank you for your answer,
can i spawn an actor from Shard actor preStart?
if yes then whenever Shard actor stoped and started on other node it automatically Spawn the other actor right?

Yes. The part about needing to remember if a child was started was more in case spawning the child is triggered by the sharded actor receiving a message.

1 Like