I'm looking for a solution to an edge case scenario where a client continually asking the server for what's new will fail.
In this example, I'm not using timestamps because of another edge case problem. That's handled in this question: A Client Walks Into a Server And Asks "What's New?" – Problems With Timestamps
Assume we're using sequence numbers. There's a single sequence number that is atomically updated every time the table is changed. When any row is updated it records the current sequence. Then it's just a matter of the client asking for what's new since the last sequence it asked for. Simple? Yes, but...
Failure scenario:
Sequence starts at 1
1) Client A starts update. Updates sequence to 2
2) Client B starts update. Updates sequence to 3
3) Client B updates rows with sequence 3
4) Client C requests changes >1. Gets B's changes. Good.
5) Client A updates rows with sequence 2.
6) Client C requests changes >3. Gets nothing. Doesn’t get Client A’s changes.
Because we're using a MongoDB, I don't believe we can easily lock the sequence during an update. And, if we could, I worry about performance.
Having clients ask "what's new" repeatedly seems like a common use case and I find it surprising not to find a better wealth of best practices on this.
Any ideas on solving this scenario or recommending a better, preferably platform agnostic, solution for asking for changes?