Probably dumb question, but I searched forum and didn’t find any clear answer (wrong keywords, perhaps):
taking into account async nature of SG, what is the best pattern to ensure that all simultaneous updates to one doc in SG will persist as if they happened in sequence?
What I mean:
Let’s say we have in SG doc containing an array [A, B, C]. Web worker (multi-treaded) recieves two different requests to change doc:
(1) SG (doc[ABC]) ==get==> doc[ABC] worker(add D) => [ABCD] ==put==> SG([ABCD])
(2) SG (doc[ABC]) ==get==> doc[ABC] worker(remove B) => [AC] ==put==> SG([AC])
If (let’s assume) these changes happen simultaneously we will have in SG two doc revisions:
[ABCD] and [AC], one of which will eventually win (if I understand _rev concept right) - and that means that one change to doc was completely lost.
The question is - what is the best way to ensure that changes happen in strict queue and resulting doc will have consistent data - [ACD] ?
I see option to implement changes queue mechanism in worker and add “locked: true” prop todoc indicating that doc is being changed right now and worker should wait and retry next change in a while.
Or there could be more simple approach?