Take the 2-minute tour ×

As I understand it CouchDb never overwrites a record but instead creates a new document with a new _rev. What happens in this scenario?

  1. User A reads a document
  2. User B reads the same document
  3. User A updates the document
  4. User B updates the document

Aren't User A's changes lost in this scenario?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

No, instead User B will get a 409 error since the revs will no longer match. For User B to commit their document, they will need refetch the document so they can get the latest document revision.

This is called Optimistic Locking, and is designed to specifically prevent the problem that you are seeing.

There's nothing stopping User B from stomping on User A's document, but now they are more conscious of it by having to refetch the document and use the new _rev parameter.

share|improve this answer
It is possible to allow user B's change so that at least B's client can successfully store an update with one round-trip. However this will cause a conflict in CouchDB which some client software must resolve. But as Will says, in most situations, people fail-early and let B (or B's software) re-run the query –  JasonSmith May 18 '11 at 0:29

Your Answer


