Consistency on a single sync gateway

I have a question about consistency in sync gateway.

If two clients both update the same doc through the same sync gateway node and then if successful read back the document to see if their write was successful.

Might they both sometimes think they are successful?
Does the read back add any extra certainly over the initial write success/failure?

In other words can I use changing document state to get a exclusive lock on the document for a single instance of sync gateway? or should I treat this as unreliable?

Thanks

p

If two clients both update the same doc through the same sync gateway node and then if successful read back the document to see if their write was successful.

By client do you mean a REST API consumer or a replicator?

In the case of a REST API consumer one of them will get there first and the second one will get a 409 Conflict in the response. For the second update to be successful it will need to retrieve the latest revision for that document.

In the case of a replicator, both revisions will be inserted and it will result in a conflict that must be resolved at the app level. The easiest way to resolve conflicts is in the app itself, the training lesson on sync covers this in detail.

I’m not sure if that answers your question though?

Perfectly. I mean with a REST client. I wasn’t sure if the second update would always fail, or behave more like the replicator case.

Thanks

P