Gapless sequential ids #15963
-
At the most basic level, I am trying to implement event sourcing. For any stream of events, I need to ensure that each event of an aggregate root ID + version is perfectly sequential. For example, if I have an aggregate root of If two systems try to write an event at the same time, my expectations is that both events would be written but first-come-first-numbered. If I up the version, I'd expect the first event written would be I know Raven can assure sequential id's across clusters & whatnot, but they can have gaps if maybe a write failed or something. Is there anything built into Raven that would absolutely guarantee a sequential number or is this something I will need to look at handling externally? If the latter, does anyone have any good ideas on how to ensure sequential numbers? It's critical that event 1 is followed by event 2 and there aren't gaps. If someone physically deletes an event, then that's on us and hopefully revisions will save us 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Hey @ItsRobbAllen - I'm curious - why is the sequential identifier important? Don't you have to track the previous event or some sort of etag to verify correctness? If two events arrive out of order from the network from different users, presumably you need to pick one or essentially resolve it as a conflict, right? |
Beta Was this translation helpful? Give feedback.
-
This is a really complex problem. On the face of it, fairly trivial, because RavenDB is transactional. You can have an operation that increments a value in one document and use that as the id for another. The reason this is complex is what happens when you are running in distributed environment. Consider the case where you have two operations to add an event to the same document, on two different nodes at the same time. A better question, however, is why do you want this? What is the importance of absolute serial values? |
Beta Was this translation helpful? Give feedback.
This is a really complex problem.
On the face of it, fairly trivial, because RavenDB is transactional. You can have an operation that increments a value in one document and use that as the id for another.
The reason this is complex is what happens when you are running in distributed environment. Consider the case where you have two operations to add an event to the same document, on two different nodes at the same time.
What do you expect will happen then?
A better question, however, is why do you want this? What is the importance of absolute serial values?