Two users working with the same root in NEventStore

I know commands are not supposed to fail, so I need to test my command before submitting.

However, if two users update the same aggregate root and both seem to be valid, we will have a concurrency issue.

How do I handle this in NEventStore? Can my clients get the version number or commit code they pass when they save the event, and if it changes then I throw an exception?

+3


source to share


1 answer


As you pointed out, one way of managing things is by specifying the version you are going to act on when you Load

aggregate (there is an overload there).

The commit phase will then [via Domain] give a ConcurrencyException

if your generated events collided with them: -

  • is already present [that you haven't loaded your aggregate].
  • written by concurrently competing processes


Make sure you> read the .doc file that the NuGet package puts into your project - it covers the basics of how JO EventStore goes about handling this.

UPDATE for clarity NB While this all works and is sometimes necessary, in general you will find [and how the default should work hard to arrive at a happy place where] You can manage most of the way your commands are naturally idempotent in nature and / or leveraging the natural conflict resolution mechanisms of your system as a whole so you don't have to rely on your event store to provide such low-level protection (e.g. etags, retrying Commands in case of conflict, etc.) ). If you go this route to some extent in practice, I would recommend discussing your strategy with sufficient real-world use cases in the DDD-CQRS list.

+4


source







All Articles