Handling Conflicts with multiple updates

I have gone through the docs for conflict management. I would like to know what happens in this case:

Case 1:

  1. User A creates doc AAA with a revision 1-aaa.
  2. User B gets the doc AAA with revision 1-aaa.
  3. User A goes offline.
  4. User B goes offline.
  5. User B updates the doc AAA with revision 2-bbb.
  6. User B updates the doc again with revision 3-ccc.
  7. User A updates the doc AAA with revision 2-ddd.
  8. User B goes online. Doc AAA is synced with gateway. Latest revision of doc AAA is 3-ccc
  9. User A goes online.
  10. Which revision will user A have of doc AAA? 3-ccc? or conflict? Is there a conflict if not the latest revision is in conflicting mode(i.e 2-bbb and 2-ddd)?

Case 2:

  1. User A creates doc AAA with a revision 1-aaa.
  2. User B gets the doc AAA with revision 1-aaa.
  3. User A goes offline.
  4. User B goes offline.
  5. User B updates the doc AAA with revision 2-bbb.
  6. User B goes online. Doc AAA is synced with sync gateway.
  7. Sync Gateway webhooks the document for quality check. It updates the document with proper formatting with revision id 3-ccc.
  8. User B gets the latest update of doc AAA 3-ccc.
  9. User A updates the doc AAA with revision 2-ddd.
  10. User A goes online.
  11. Which is the latest revision of doc AAA? Is there a conflict? Will user A get the 3-ccc ignoring 2-ddd? If there will be conflict, than getting conflicted revisions gives me doc 3-ccc, or only 2-bbb and 2-ddd?

In both your examples the “current revision” as reported by the library will be the one with the higher revision number. In reality, you should think of things in terms of leaf nodes in an ongoing tree. If you have more than one leaf node that is not deleted then you have a conflict. In both cases, your two leafs are 2-ddd and 3-ccc on both devices. So the answer to your question about which revision the user will have is “both.” It’s up to the local app to decide which one is the one to use going forward. You can either leave it up to the library, in which case the longest branch in the tree wins (3-ccc) or you can check the conflicting revisions on a document and decide what to do (choose a winner, merge, etc). Both user A and user B will have the graph below and the leaf nodes (those in boxes) are guaranteed to have body information intact.

 1-aaa+------+
   +         |
   |         |
   |         v
   v      +--+--+
 2-bbb    |2-ddd|
   +      +-----+
   |
   v
+--+--+
|3-ccc|
+-----+

Couchbase Lite will be showing this as a conflict, right?

Yes, this is a conflict and you will see both of these revisions in the conflictingRevisions property.

Okay ! Thank you so much ! :slightly_smiling: