I am interested in developing a library that would sync a core data model across devices via the Parse mobile backend. I want to mirror the functionality that iCloud core data sync attempts to provide.
Why not use iCloud or Ensembles? I am currently using iCloud core data sync in a production app and it is not working well for me. I also want to provide authentication independent of the Apple ID which is another reason I want to get away from iCloud. As far as Ensembles is concerned, I am not sure if this will still work with Dropbox due the deprecation of the dropbox sync API.
I haven’t begun to develop the library. I am looking for feedback on my plan which is outlined below. This design is based off of this SO answer.
General design of the library:
The library would provide a standard core data stack that would set up the persistent store coordinator and managed object context. All of the standard core data CRUD operations would proceed through an interface provided by the library.
Each time CUD operation takes place, a sync operation object would be saved to Parse in the background that includes all of the information needed to reproduce the operation. This includes: the type of operation that took place, a unique identifier for the object that was operated on, and in the case of a create operation, the parent object and relationship would be provided.
- Each operation would have a change_id number associated with it. Every time the device downloads and executed an operation, it would store the latest change_id associated with that operation.
- Prior to uploading each sync operation, the device would send a request to the server to ensure that the change_id number stored matches the one stored locally. If the change_id on the server is higher, it would first download all of the sync operations and execute them then upload its own sync operations.
- Conflicts (two devices editing the same value while offline) would be resolved by determining which device changed the value last.
Am I missing anything here? What are some potential pitfalls with this approach? I hear that sync is hard, should this type of undertaking be left to the most experienced developers?