Ok, I realize this is hacky/bad. But bear with me…
Is it possible to use the event store’s stream version to implement a distributed numeric id assignment. For example:
Simultaneous actions on stream with maxCount = 1…
node1: read stream -> event version = 7 -> save blank event, expected version 7 -> pass -> next id = 7
node2: read stream -> event version = 7 -> save blank event, expected version 7 -> fail -> retry
read stream -> event version = 8 -> save blank event, expected version 8 -> pass -> next id = 8
Node 2 could get stuck retrying indefinitely if the load was heavy enough. But that won’t happen for my purposes (small percentage of use cases). What other issues could come up?
So, basically I’m trying to avoid having to put yet another DB in service just for the SQL identity column. As it would have to be highly available in our system, and we already have 2 databases in play (clustered event store and non-clustered read model document dbs).
I don’t need strictly serial numbers, but I do need a reference number for a certain type of aggregate. It doesn’t have to be assigned right away, either.
Right now my other best option is to have a maxCount = 1 stream like above, but from a fail-over numbering service (or maybe hilo type service) so the event store save happens only on the active node. But that’s still another failover service to manage configuration on. I used to be an admin, so maybe I’m trying to hard to save configuration points…