Append failed due to WrongExpectedVersion

The following scenario occurred on our system this weekend:

  1. Our bounded context received two events at the same time from our subscriber service, the events are named VerificationRequestedEvent & ValidationRequestedEvent.

  2. Each event is handled by the re-hydrated aggregate which has an current event count of 32.

  3. The VerificationRequestedEvent completes first and adds a new event to the aggregate, VerificationSuccessfulEvent (event 33).

  4. The ValidationRequestedEvent event subsequently completes and attempts to also add new event to the aggregate named ValidationSuccessfullEvent. However as the aggregate was at event count 32 when the ValidationRequestedEvent event was

handled it attempts to write event 33 which has already been written. This give us the following error:

EventStore.ClientAPI.Exceptions.WrongExpectedVersionException: Append failed due to WrongExpectedVersion. Stream: Sender-d2b798d15bb24479b89c2e69f6f5d8df, Expected version: 33

What is the best solution/way forward with this issue?

This is expected behaviour... you can also use ExpectedVersion.Any if
you don't want to explicitly set a version for concurrency purposes.