Repository navigation
Replies: 1 comment 1 reply
|
Hey man, this came up for the very, very first time last week and I admittedly told someone that this was more or less a completely bonkers use case. I'm moving this to a discussion. I think this would be extremely hard to support. My suggestion would be to only use one single stream projection that catches every possible event type, then use a |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The base question here boils down to: If I have multiple, different SingleStreamProjections for the same stream that only care about certain events, should the
Versionin the JSON body of these SSPs be the same or different and should themt_versioncolumn be the same or different?Example
Using the IncidentService / HelpDesk example that is often used, let's pretend that you have the following events:
And now let's say that you want to have multiple SSPs to serve your UI. In this scenario, let's say you have two pages on the UI: Details page & Notes page. The details page, as the name suggests, contains all the basic details of the incident. The notes page, also as the name suggests, contains all of the
AgentRespondedToIncidentandCustomerRespondedToIncidenteventsSo we have an IncidentDetails projection and IncidentNotes projection. Both are registered as
inline.Our IncidentDetails projection has an
Apply()method for all 9 of the events mentioned above. Our IncidentNotes projection has anApply()method for only:IncidentLogged,AgentRespondedToIncident,CustomerRespondedToIncidentSo now let's say we have this flow:
If we examine the
mt_streamstable, the stream's version is 4.If we examine the
mt_doc_incidentdetailstable, both the version in the JSON body and themt_versioncolumn have a value of 4If we examine the
mt_doc_incidentnotestable, both the version in the JSON body and themt_versioncolumn have a value of 3.Problem
If we have multiple SSPs for the same stream to feed pages of our UI (because we only care to get the info we need), but the versions differ due to the above example, then we have the wrong version value on the frontend when it comes to doing a POST/PUT/PATCH request to the backend, and that results in a concurrency exception.
So should SSPs for a stream have their version incremented regardless of if they have an
Apply()method for all events?Repro
I've cloned the IncidentService from the WolverineFX repo here: https://github.com/ross1296/IncidentServiceExample/
All I've done is:
I then make the following HTTP requests:
The result is:
Justification
I'm fully aware that I may be misunderstanding something here, or perhaps(?) this isn't idiomatic usage, but is it not reasonable to create multiple SSPs to feed UI pages in order to keep the request/response as small as possible, and also ensure strong consistency from UI > Backend?
I refer to this blog post: https://jeremydmiller.com/2023/12/05/building-a-critter-stack-application-dealing-with-concurrency/
Which states: "Marten will “automagically” set the value of a Version property of the aggregated document to the latest revision number of the event stream. This (hopefully) makes it relatively easy for systems built with Marten to transfer the current event stream revision number to user interfaces or other clients specifically to make optimistic concurrency protection easier."
But from the demonstration above, it does not appear that all SSPs have their Version property set to the latest revision number of the event stream. But instead, only by the events which the projection implements.
All reactions