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?

  • Could you please specify what application you are creating (web-based, mobile, etc.)?
    – superM
    Oct 25, 2012 at 10:51
  • It'll be across multiple platforms - mobile, desktop, web
    – Harry
    Oct 25, 2012 at 11:02

2 Answers 2


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.

  • Yep, I am using GUIDs. What do you mean by deleting data? What needs to be thought about?
    – Harry
    Oct 25, 2012 at 12:01
  • 1
    @Harry - if you delete data on the client, you need to record the fact that it's deleted, and the time. When you sync, you need to check if the record was modified on the server after that time (conflict). Also, you need to record when something was deleted on the server so you can sync that to any clients. Oct 25, 2012 at 12:05

You may want to look at some pre-built document storage solutions such as CouchDB that are optimized for replication. It speaks natively in JSON which is a plus for your needs. MongoDB is another possibility but CouchDB has been more optimized for peer-to-peer replication in the past for this scenario, although MongoDB is catching up in that area.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.