Syncing objects to a remote server, and caching on local storage

cachingsynchronization

What's the best method of sycing objects (as JSON) to a remote server, with local caching?

I have some objects that will pretty much just be plain-text with some extra meta-data. I was thinking of perhaps including a "last modified date" for both Local storage and Remote storage. This could then be used to determine which object is the most recent.

For example, even though objects will be saved to both local and remote when they are saved, sometimes the user may not have internet access, or the server may be down, or any other number of things. In this case, the last modified date for remote storage would be reverted to its previous date. Local storage would remain as it is. At this point, the user could exit the application, and when they reload the application would then look at the last modified dates of the local and remote storages, and decide.

Is there anything I'm missing with this? Is there a better method that I could use?

Best Answer

For some good ideas, check out how Microsoft Sync Framework works.

You have the right idea. You need a last modified time, but you also need to think about deleting data. You need a tombstone table for that. Plus you then have to write some custom logic on how to deal with conflicts (what if two clients updated the same record?).

One thing is make sure you're using UUID (Guid) for your IDs, that way they can be created in multiple locations simultaneously without collisions.