Syncing a local store

I want to make an Offline-first application. I am considering using standard CoreData for that. The collaborative and syncing features are to be handled through Parse.

To keep my CoreData in sync, I expect to

  • need to monitor for changes (LiveQueries)
  • download changed objects at launch (get all objects changed since last sync)
  • upload changes as they happen, retry when entering background/launching the app if it failed

I’ll probably going to use some hashing of the data + recipe.updatedAt to detect conflicts. I’ll adopt a last change wins strategy to start but I’ll investigate a “merge UI”. I don’t expect concurrent edits to happen that often, I only need to handle offline editing/bad network.

My question resides around deletes. I’ll see them with the LiveQuery but only when the app is running. What about deletes that happens when the app isn’t running? I could run a query for all recipes IDs and compare them, delete anything that is missing. I don’t expect users to have more than 5000 records, so in the end this isn’t too expensive but I wonder if there’s a better solution?

I could leave records in place instead of deleting them and mark recipes with a isDelete column but then they’ll be forever there.

Suggestions?

Your ideas sound like good ones to me. Its similar to how my middleware, ParseCareKit

works which keeps the local core data store in sync using vector clocks with Parse in the sample app I posted on the other thread. It’s basically a synchronized distributed database. To get some ideas on how to setup your core data store for something like this, I recommend looking at Apples CareKit (specifically the OCKStore):

1 Like

Great, I’ll have a look at the source :blush:

For those looking for local data storage in ParseSwift, I recommend coming up with approaches like @pierlux above. If anyone would like to develop a protocol based modular solution for ParseSwift. The links I provided above may provide insight on a approach. Note that this is different from the other SDKs on purpose to provide more flexibility to the developer. You can see a discussion about the limitations of the current local storage approach in some of the other SDKs here and why we currently believe a protocol approach would be better. This would enable “adapter” (if you are familiar with developing for the Parse Server) style local storage for developers to chose. Third parties would then be able to implement their own local storage adapters.

If anyone would like to tackle this problem, have a look here:

and feel free to submit a Issue/PR to start the discussion.

There’s even a Swift DotVersionVector that could be useful.