How can I merge multiple revisions of notes together into a single version? How can I merge multiple revisions of notes together into a single version? mongodb mongodb

How can I merge multiple revisions of notes together into a single version?


I had to deal with a similar issue in the past (syncing offline events).Here what we did in general, hope it would help.

  1. The app does not initiate a sync

You want to minimize the timeframe where sync issues can rise.

This can be solved by triggering sync observing the state of navigator.online.1. when it changes to false, start buffering the user edits.2. when it changes to true, pull the new changes from the server, then push buffered actions.

  1. Merging of the two notes...

This can be quite challenging. It really depends on the type of data, and how tolerant are you to sync errors.

We found that its best to handle sync issues as close to the source as possible. We contained the sync issues at the client side, so corrupted data would never reach the DB.

The sync itself behaves like a git merge.

When the offline device pulls the updated data, it would attempt to merge the buffered actions before sending it to the server.

  • if a conflict is detected, it would try to auto-correct it. adding timestamps to every action may help to sort the order of actions from multiple devices.
  • if auto correction fails, it would prompt the user to resolve it manually.

I Hope it helps.


Well basically there is no magic solution for this problem. This is very common problem and solution depend on business requirements, first of all I suggest you to read Designing Data-Intensive Applications, this book explain exactly those kind of problems.


This is a common problem, especially for mobile environments. An interesting approach is to use Service Workers in a Progressive Web App. These will hold your network requests until the user is online again, and then process them when back online.

This article can explain this approach in more detail than I could here:

https://developers.google.com/web/updates/2015/12/background-sync

NOTE: this was written in 2015, and things have progressed a lot on this front. Service Workers aren't available yet in iOS, but they are expected to be supported within the next couple or years.