JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.75k stars 429 forks source link

Event race conditions #3214

Closed NQuirmbach closed 2 months ago

NQuirmbach commented 2 months ago

Hey,

I'm not really sure where to post, since it's not really an issue, but more a lack of understanding :laughing:

I have a service, that receives two different event types from different sources. In my example it's users and todos. My goal is to create is a projection that contains all info from the todo and the assigned users.

Here a my models (simplified for testing purpose)

User Event record UserCreated(Guid Id, string FirstName, string LastName)

Todo Event record TodoCreated(Guid Id, string Description, Guid CreatedBy, Guid ChangedBy)

My projection should look something like this record Todo(Guid Id, string Description, User CreatedBy, User ChangedBy)

Due to the nature of event driven, when processing the Todo event, it is not guaranteed that the User already exists. Additionally in the future, I want to update the projection if a user changes.

I've played around the MultiStreamProjection and Custom Grouping, but not really get a sufficient solution. Sample repo can be found here: https://github.com/NQuirmbach/marten-race-conditions/tree/setup-event-consumer

Hope you could help me here :smile:

jeremydmiller commented 2 months ago

You might want to take this to Discord instead and get in from of more people. I'm converting this to a discussion, but Discord is more widely read