gautema/CQRSlite

Race condition in Repository

ygor opened this issue · 1 comments

ygor commented

Isn't there a possible race condition in the Save method of the Repository class? Furthermore, how to fix concurrency issues between multiple instances of a service (or should one then consider the actor model instead) ?

Hi.

There are some issues here. They are really hard to take care of in the repository without locking the whole system down during save. For that reason I have not attempted to fix these issues here. I rather encourage not to publish events from the repository but rather from the event store. Other issues will also need to be addressed from outside, either by database transactions or as you say, actors with one aggregate per actor would work.

Multiple instances of a service is an even harder problem to solve, but the same applies here. Either some sort of database guarantees or keeping one aggregate in only of the services and do some routing. I've also heard about someone cleaning up and fixing extra events on later reads.