CRUD operations order


Is the order of CRUD operations guaranteed in java SDK (2.1.2) to be the same in the couchbase (3.1)?

Let’s say I have in couchbase a document with id: “1” and I asynchronously emit operation up1: upserting that document again. Then immediately (let’s say few nanoseconds later) I emit also asynchronously operation d1: delete document with id “1”.

Am I guaranteed that up1 will be applied before d1, so at the end I’m sure that the document with id “1” is removed?



Operations are queued in order in the client, so they should hit the server in order (and the server executes the operations in receiving order as well). So far so good :smile_cat:

However, there could be corner cases :scream_cat:
Imagine the node was failed over and is in the process of being brought back up. The window you describe is very narrow (nanoseconds), but in such case, with the default RetryStrategy of the SDK, the requests will be queued for retry with an exponential backoff during the failover period.

So it could be that the first request is scheduled for retry, the server node finally goes back up and the second request (delete) is successful. Then the upsert would be retried and the document would be re-created.

:bulb: Note that maybe in that particular example you can choose to use update instead of upsert, seeing as this will fail if the document doesn’t exist.