Checking for stale results with Position and CatchUpSubscription

In order to prevent serving stale results, I’m using position to track where the Read Model is “up to” like so.

  1. Write returns position
  2. Position is sent back to the client
  3. Client makes a query and forwards the position it received
  4. If client Position is greater than Read Model Position the result is stale

Now the problem comes from the Read Model being built using a CatchUpSubscription, because if an event happens to be handled with catchup (as opposed to live) the OriginalPosition is null. I haven’t been able to figure out how to get it. So the Read Model doesn’t know the position of the event, therefore, you can’t tell if a query is stale or not.

Is there something I’m missing or is there a way to get the OriginalPosition?

Simiular topics:

https://groups.google.com/forum/#!searchin/event-store/position$20readmodels|sort:date/event-store/r0KwwTXZ_dI/Af6SMSRQBAAJ
https://groups.google.com/forum/#!searchin/event-store/position$20read$20models|sort:date/event-store/c0fwz-llmr0/dOqPnBAoAgAJ

There is a position on the event you receive depending on the type of subscription https://github.com/EventStore/EventStore/blob/release-v4.0.4/src/EventStore.ClientAPI/ResolvedEvent.cs#L49 https://github.com/EventStore/EventStore/blob/release-v4.0.4/src/EventStore.ClientAPI/ResolvedEvent.cs#L39

I appreciate the reply Greg, however, those links point to OriginalEventNumber and OriginalPosition both of which have issues.

  1. ResolvedEvent.OriginalPosition is null for catchup events (as stated in my original question).
  2. ResolvedEvent.OriginalEventNumber is only unique per stream which is not useful in this case.
    Is there any way to force OriginalPosition to be sent/not null while a CatchUpSubscripton is not yet live (aka still catching up)?

See caveat (depending on type of subscription type). https://github.com/EventStore/EventStore/blob/release-v4.0.4/src/EventStore.ClientAPI/RecordedEvent.cs#L26 is what you want for a stream. For a subscription to all you want https://github.com/EventStore/EventStore/blob/release-v4.0.4/src/EventStore.ClientAPI/Position.cs positions are included on responses https://github.com/EventStore/EventStore/blob/release-v4.0.4/src/EventStore.ClientAPI/AllEventsSlice.cs#L24

In my case, I think I need a Stream Subscription so that I can filter out the events I don’t care about.

So to confirm, you are saying Position won’t be included for Stream Subscriptions, and the only way to get it is to use $all instead?

For a stream you want to use the position in the stream (it is an monotonically incrementing sequence that is included on the event)