Skip to content

One stream, multiple SSPs, different versions & strong concurrency #3956

Closed

Description

@ross1296

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 Version in the JSON body of these SSPs be the same or different and should the mt_version column be the same or different?

Example
Using the IncidentService / HelpDesk example that is often used, let's pretend that you have the following events:

  • IncidentLogged
  • IncidentCategorised
  • IncidentPrioritised
  • IncidentClosed
  • AgentAssignedToIncident
  • AgentRespondedToIncident
  • CustomerRespondedToIncident
  • IncidentResolved
  • ResolutionAcknowledgedByCustomer

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 AgentRespondedToIncident and CustomerRespondedToIncident events

So 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 an Apply() method for only: IncidentLogged, AgentRespondedToIncident, CustomerRespondedToIncident

So now let's say we have this flow:

  • LogIncident endpoint, which returns an IncidentLogged event
  • Then we hit our CategoriseIncident endpoint, which returns an IncidentCategorised event
  • Then we hit the CustomerRespondToIncident endpoint, which returns the CustomerRespondedToIncident event
  • Then we hit the AgentRespondToIncident endpoint, which returns the AgentRespondedToIncident event

If we examine the mt_streams table, the stream's version is 4.

If we examine the mt_doc_incidentdetails table, both the version in the JSON body and the mt_version column have a value of 4

If we examine the mt_doc_incidentnotes table, both the version in the JSON body and the mt_version column 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:

  • mt_streams version: 2
  • mt_doc_incident version (data and version column): 2
  • mt_doc_shortincidentdetails (data and version column): 1

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.

Activity

  1. changed the title [-]Multiple SSPs & different versions[/-] [+]Multiple SSPs, different versions & strong concurrency[/+] on Sep 17, 2025
  2. changed the title [-]Multiple SSPs, different versions & strong concurrency[/-] [+]One stream, multiple SSPs, different versions & strong concurrency[/+] on Sep 17, 2025
  3. jeremydmiller commented on Sep 17, 2025

    @jeremydmiller
    Member

    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 Live lifecycle for everything else and always use FetchLatest() or FetchForWriting when fetching the others.

  4. locked and limited conversation to collaborators on Sep 17, 2025
  5. converted this issue into a discussion #3957 on Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions