Skip to content

Instantly share code, notes, and snippets.

@Restuta
Last active December 14, 2015 00:49
Show Gist options
  • Save Restuta/5001434 to your computer and use it in GitHub Desktop.
Save Restuta/5001434 to your computer and use it in GitHub Desktop.

The problem

In case when one command results in several events for the same AR those events could happen really fast, so DateTime.Utc.Now returns absolutely equal dates and two events get written with the same date to the EventStore. When they are queried later and sorted by EventDate the resulted order is unpredictable.

I faced this issue trying to replay events locally from our Dev db, there are two events

id: d85cd1d4-b0d0-4e7f-8d08-4b6e8638e61d, UserCreatedEvent, AggregateRootId: 42668cc6-da9e-44f1-ba05-105f55ebea34

id: 44b75b0c-cb43-482b-8b95-37b73ad1b0de, UserCredentialsCreatedEvent, AggregateRootId: 42668cc6-da9e-44f1-ba05-105f55ebea34

and they get returned in logically incorrect order UserCredentialsCreatedEvent first, since they have equal dates. I am not really sure how to solve this problem. Any thoughts?

@faizaamer
Copy link

Would the DateTime ticks help?

@Restuta
Copy link
Author

Restuta commented Feb 21, 2013

No, DateTime is a complex object, ticks is just one representation of it, when I say "absolutely equal" I mean dateA == dateB returns true. @faizaamer

@Restuta
Copy link
Author

Restuta commented Feb 21, 2013

The only way of resolving this I see is to create some global sequence for events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment