asynkron / protoactor-dotnet

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
http://proto.actor
Apache License 2.0
1.73k stars 288 forks source link

[Proposal] Proto.Persistence.IEventStore should provide PersistEventsAsync that accept multiple events as argument #1739

Open mjaric opened 2 years ago

mjaric commented 2 years ago

Currently Proto.Persistenece.IEventStore only supports persisting single event at the tame.

Task<long> PersistEventAsync(string actorId, long index, object @event);

This may not be good option for some cases. For instance, (and this just my preference) if we are using journal db like EventStore, the client will create ACID until that single event is persisted in EventStore regardless there are other events in batch that should belong to that same ACID transaction.

As a consequence to above case, some other instance could host same persistent actor and write another event. There is very small possibility that this may occur, but again, may produce later false state in Aggregate due unintended event ordering.

I would like to extend IEventStore interface with another function with following signature

Task<long> PersistEventsAsync(string actorId, long index, object[] @event);

This would help utilize EventStore ACID transactions on steam while appending batch of events to it, plus, prevent incidental appends from other "sources" until transaction completes.

I'm open to create PR. Let me know if you are OK with this suggestion.

Thank you

dystopiandev commented 2 years ago

It's not a very small possibility actually. I ran into this issue while migrating events from one database to another. Happened randomly, so it took a painful while to figure out how it was possible for the order to get mixed up.

originswift-sys commented 2 years ago

@mjaric did you find a way around this?

mjaric commented 2 years ago

@mjaric did you find a way around this?

I created my persistence plugin. But I can create PR. Tho in such case I have to update all plugins in this repository 😅 before it ends in nuget.

mjaric commented 2 years ago

One more thing. Since, comparing to akka.net, proto.actor actually do not require from you to create system actor that extends this framework in order to add eventsourcing. I think you can create your abstract repository and go that route, one aggregate root, one repository.... I like this because everything becomes much simpler to test where in akka you are tight coupled to test kit and your BDD test case start to look like integration test... but that's just opinion.