0

Let us imagine we have an object D, containing some data. This is modified differently across two different locations, giving rise to data objects D1 and D2. Depending upon the contents, D1 and D2 may be in conflict with each other when being merged back as part of a synchronization process.

Systems such as version control systems simply point out that the two data objects are in conflict with each other and leave it upon the user to manually resolve the conflict.

However, let us now imagine a consumer-facing application, such as a note-taking application that synchronizes contents online. In this case, no user will want to manually resolve conflicts that may have arisen due to the user typing out two versions of the same note with different contents. Discarding the older object for the newer object isn't possible either, since there may be valuable content in the older object that the user wants.

How should I go about resolving such conflicts in a consumer-facing application?

  • 1
    This issue is exactly why VCSs leave it to users to manually resolve the conflicts. If there is no identifier of correctness, ie, which must be kept and which rejected, you cannot do it from the code. – vish4071 Aug 25 '16 at 18:37
  • Very true, and even the case where a VCS is able to automatically merge changes, this does not mean that the result is without conflict. Only a human will be able to determine [related answer](http://stackoverflow.com/a/38464406/23118). – hlovdal Aug 26 '16 at 22:24

1 Answers1

1

Well, if you don't want manual conflict resolution, then you will have to automatically merge changes from both updates.

There is no way that works well for all applications. When you have a requirement like this, you have to carefully design the application so that automatic merging makes sense.

There are a few common approaches, and you can do one or all of them in various combinations:

1) Merge updates really fast. Think google docs -- updates are merged in real time as people edit. Operational Transformation (https://en.wikipedia.org/wiki/Operational_transformation) is a good way to understand exactly how to do that kind of merging, but it doesn't have to be as complicated as that doc. The reason this works well is that updates are small and you can tell if someone is messing with your stuff before you put a lot of work into it. Politeness fixes conflicts -- one of you will wait until the other is done with that stuff.

2) Locking. If you click the edit button on a note, make lock it so that nobody else can edit it until you're done, etc. This is old-school, and not nearly as slick as (1), but it can work in situations where you can't merge fast enough to do (1).

3) Design your data model and interface to make merged versions as nice as possible. If anyone can add notes, but a note can only be edited by its owner, then no problem, for example. Or maybe you can only edit my stuff if you ask permission first and I give it to you. As things get more complicated than that, this becomes increasingly difficult. It's not usually possible to do this well if you're not willing to make sacrifices in application functionality. You've got one thing on your side, though: It's rude to mess with someone else's work, so a lot of the things you can do look like you did them just to enforce good behavior, and users will thank you for them if you did it with finesse.

Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87