Couchbase sync gateway server side conflict resolution

Hi guys!
If I understand correctly, the philosophy of Couchbase sync conflicts resolution is to always resolve it on device. I would like to know if it’s possible to have the conflicts resolution on the server side? So an example scenario would be:

  1. Device initiates the sync and sends all his changes to the server
  2. Server detects the conflicts and merge them
  3. Device receives updated changes (the newest revision, with all conflicts resolved)

Is this scenario possible? If so, what would be the best way to implement it?

Best Regards,
Abhay

You can be notified of conflicts on the server side by using the changes speed with the conflicts parameter in the querystring http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/sync-gateway/rest-api/database/get-changes/index.html

Then, your app server resolves the conflict by creating a new revision with the desired properties and deleting all other non current revisions.

James

Hello @jamiltz
Thanks for your help…
Do you have any sample code for this solution?

Abhay

No, but you could look for one for CouchDB since the API is the same for conflict resolution.

James

Hello @jamiltz

Thanks for your suggestion.

I need your expert input to solve one problem. We have application in which data is updated from Web and App (IOS), So in our case data is updated from both side. From web data is directly updated in main bucket and from App(iOS) data is updated in shadow bucket using sync gateway, so in our scenario we have more chances of conflicts in documents during synchronization.

Regarding implementing conflict resolution on server-side at Sync Gateway, based on your input if I understood correctly we have to call _changes rest API from other source and then we have to add listener on this API to get continuous conflicts data. I have some confusion so if you can help me to understand the flow of execution inside Sync Gateway which helps me to implement the conflict resolution logic at right place.

Suppose if we add listener out side the sync gateway and sync function executes first than in that case document get updated twice. First sync gateway during normal sync and 2nd from our manual conflict resolution code/process.

So in this scenario if you give your expert view on how & where to implement conflict resolution logic thus we implement it right way. IF you know internal flow of Sync gateway than please let us know so it will help me to take right decision.

Please share your expert view and share all details regarding how to implement conflict resolution at server side using Sync Gateway.

Thank you
Abhay