Let's say I want to use CosmosDB for Event Store, where have single collection for all events. Currently it is not horizontally partitioned, but it is a possibility for future.
Now, I need to implements event handlers, ideally as Azure Functions, but AppService will work well as well.
Do you have some guide, how to implement the messaging between event store and event handlers reliably?
I need to have guarantee, that
Every event that is saved to the DB will be delivered to all event handlers once and exactly once (not zero, not two times)
When replaying the events, they have to be processed in the same order as when they were first handled.
Of course, I would like to keep the latency between event store and event handlers as low as possible.
What is my problem?
The requirement #1 disqualifies all event store implementations, that relies on pushing events to some message bus, because that operation is not granular and some events could possibly stay undelivered.
In my current solution is each event handler keeps track of last processed event,
I would maybe pull the events from event source (the pull could be triggered by Cosmos DB triggers) and then deliver to the event handlers, but then event handlers needs to keep track of what events have been handled and I don't want to do this on my own from scratch.
The other problem is the event orders. Since there is no built in auto incremented column, how to guarantee, that I retrieve the events always in the same order?
- Given events T1, T2a and T2b
- When T2a and T2b have the same timestamp
- When query at time T2 returns events
- Then the same query at later tile won't return
T1, T2b, T2a...
Does ComsosDB support this out of the box?