The-Inevitable-Event-Centric-Book icon indicating copy to clipboard operation
The-Inevitable-Event-Centric-Book copied to clipboard

Problem: Handling Concurrency

Open ylorph opened this issue 3 years ago • 4 comments

  • @MerrionComputing concurrency 🐊
  • pessimistic:
    • checkout / checkin
  • optimistic locks
  • no concurrency
  • stream design
  • merge
  • deduplicate
  • Actor Model

ylorph avatar Apr 20 '21 07:04 ylorph

Does the actor model handle concurrency or more prevent it (by being effectively synchronous single threaded inside the actor)?

MerrionComputing avatar Sep 07 '21 14:09 MerrionComputing

well it a way to prevent concurrent append to a stream , as well as keeping it's projectected state in memory. ( if only 1 actor has ownership of appending to a stream )

ylorph avatar Sep 15 '21 09:09 ylorph

Added some thoughts in this article: https://github.com/MerrionComputing/Presentations/blob/master/Articles/taming-the-concurrency-crocodile.md

MerrionComputing avatar Jan 07 '22 14:01 MerrionComputing

I've been working on this problem in Evently, and came up with a solution I'm calling Atomic Append. Basically one creates a selector to look for events across all streams in the ledger, and then if the read model from that stream is satisfactory, Evently will use that same selector to atomically append the new event. If the selector has new events in the interim, it rejects the append and the client can try again with another hydration or communicate the failure. This is similar to Solution 3 in @MerrionComputing's article, but simpler.

The example I use in Evently is Account Registration where one can only register unique usernames. First a command looks for account registration events where the username in the event matches the command's username. If no events are found, the append request is sent using the selector ID. Evently checks the selector and appends the event if the attached selector selects no new events. This atomicity mirrors the SQL Atomicity and its INSERT / UPDATE ... WHERE statements.

mattbishop avatar Aug 14 '23 19:08 mattbishop