0

Being a complete noob to the actor model way of doing things, I a struggling to understand how I would store transaction history in an Actor Model. In the example from ProtoActor Persistence (https://github.com/AsynkronIT/protoactor-dotnet/blob/dev/examples/Persistence/Persistence/Program.cs) the child actor produces a bunch of random names like this:

public Task ReceiveAsync(IContext context)
{
    switch(context.Message)
    {
        case Started _:
            context.Self.Tell(new LoopParentMessage());
            break;
        case LoopParentMessage msg:
            Task.Run(async () => {
                context.Parent.Tell(new RenameCommand { Name = GeneratePronounceableName(5) });
                await Task.Delay(TimeSpan.FromSeconds(2));
                context.Self.Tell(new LoopParentMessage());
            });
            break;
    }

    return Actor.Done;
}

And the parent then updates it's state like this:

private async Task Handle(RenameCommand message)
{
    Console.WriteLine("MyPersistenceActor - RenameCommand");
    _state.Name = message.Name;
    await _persistence.PersistEventAsync(new RenameEvent { Name = message.Name });
}

The question is, in an actor model, how should I store and retrieve a list of the previously generated names to display to the user.

Do I just store them in a separate database table? That seems a bit wasteful because I have already stored the events in the Event Store. So then should I use the Event Store as the journal? That also feels like I am mixing concerns of the events.

Another way of asking this: If I have a bank account modeled as an actor, how should I store the transaction history so that I can show it in the UI and not just the current balance?

  • 3
    It's unclear to me what you think the problem is here. If you've already stored the information you need somewhere, why on earth would you not make use of it? – Robert Harvey Aug 3 '17 at 15:53
  • @RobertHarvey that is what is unclear to me too. I have looked at Akka.net, ProtoActor and Project Orleans and none of them have a clear way to query the events that have been stored. Nor can I find a single demo example on the web showing the transaction history being queried. I suspect I am just missing something obvious or thinking about this wrong – Geoff Aug 3 '17 at 20:06
  • 1
    In any other system not using the Actor model, yes, you would have to store this information in the database. Your question says you're storing this information in the Event Store. Why can't you retrieve it? Is the Event Store write-only? That doesn't seem very useful. – Robert Harvey Aug 3 '17 at 20:22
  • So in the all the actor systems that I have looked at, the interface for the event store is more about restoring state by replaying the events than being an actual data store. Sticking with Proto.Actor, it seems as though the event store is set up to discourage the use of it for querying with its callback for the events. (github.com/AsynkronIT/protoactor-dotnet/blob/…) It feels like I am going against the grain here and that I am missing a more idiomatic way to do this. – Geoff Aug 3 '17 at 20:31
0

Use a table for each relation:

Actor Relational Database

To simulate the workings of one store, we created eight Store Section actors. For each, we loaded the inventory relation with 10,000 items and the purchase history relation with 300 entries per item for a total of 3,000,000 entries, simulating a history of 120 days where 500 customers on average visit the store per day and buy 50 items each. We fix the number of Group Manager actors to 10 and vary the number of Cart actors depending on the experiment. The number of Customer actors is set to 30 times the number of carts.

References

protected by gnat Sep 9 at 9:11

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.