Two inserts at exact same time

We are planning to use Couchbase documents for an application locking system,

It is guaranteed that inserting two documents in the same key, at exact same time. One of then will always fail with ‘DocumentAlreadyExistsException’ ? (We are using the Java client)

Our use case would be something like this: some process want to start, but first will try to insert a certain document with a certain key, (with a expiration time also).
If the document was inserted with success process with Start.
If the insert failed, process can’t start.

Thanks in advance

Yes - the server will pick an ordering for the two inserts, one will happen first (and succeed assuming the key doesn’t already exist); the second will fail.

2 Likes