These are chat archives for akkadotnet/akka.net

11th
Mar 2018
Havret
@Havret
Mar 11 2018 11:59

What are your strategies for dealing with Persistent Children? Let's say I have a ChatManager actor which controls and supervises all the chats in the system. Actual chat conversations are handled by its children -ChatActors.

When a request for new conversation arrives a new ChatActor is created under the ChatManager supervision. When my system crashes, I would like to restore it to the previous state which includes recreating all the ongoing chat conversations. My strategy, for the time being, was to implement ChatManager as a persistent actor and preserves ChatCreatedEvents and ChatEndedEvents to build the internal list of ongoing conversations. After all the messages are successfully replayed I just create ChatActors respectively.

There are a few problems I see with this implementation:

  • I have to preserve ChatCreatedEvent and ChatEndedEvent twice. In ChatManager and in ChatActor scope.
  • I don't need all props of ChatCreatedEvent and ChatEndedEvent to build the internal list of ongoing conversations. All I need are the names (which are Guids in this case).

Am I doing sth wrong? Or it this the right way?

Ondrej Pialek
@ondrejpialek
Mar 11 2018 12:32
I am no expert but due to the lack of responses I'll chip in my two cents ;)
What you are describing is more or less what I would, except maybe persisting different events for the manager - with just the info it needs.
An alternative approach would be to build a projection of the ChatActor's events only based on the two events you are interested in. This way you would not persist another pair of events and only start those children that are still ongoing.
Yet another approach would be to use Cluster Sharding backed by Persistence that can restore your actors when they migrate between shards, but that would not survive a system-wide crash and would require you to use this distributed-centric system, which I am not sure if it's applicable in your environment.
Onur Gumus
@OnurGumus
Mar 11 2018 19:36
How does supervision work with remote actors?
Marc Piechura
@marcpiechura
Mar 11 2018 20:09
@OnurGumus the same way it works for local actors 😄
But I assume you have a specific scenario in mind?
Onur Gumus
@OnurGumus
Mar 11 2018 20:10
Nope
Marc Piechura
@marcpiechura
Mar 11 2018 20:11
Supervision works only at local basis since your local actor can’t be the parent actor of an remote actors
Onur Gumus
@OnurGumus
Mar 11 2018 20:11
eh?
I think local actors can be parent of remote.
It is documented in remote deploying actors
Marc Piechura
@marcpiechura
Mar 11 2018 20:13
Could you point me to the docs ? Even with remote deployment I wouldn’t think your local actor becomes the parent but I could be wrong
Bartosz Sypytkowski
@Horusiath
Mar 11 2018 20:20
@Havret it looks like a good scenario for cluster sharding.
Marc Piechura
@marcpiechura
Mar 11 2018 20:20
Yeah ok, logically it’s indeed the case :)