xotix
xotix

Reputation: 530

Most current edit on Mobile<->Web App Two Way Syncronization

The title basically says it. I have an application which is usable as a web app anda mobile app. The mobile app receives and sends data to the server. There are several cases to cover when doing a sync but I need to somehow know which is the most current edit. I plan to sync at start and stop of the mobile app. The most difficult case is probably when the user starts the app without internet and closes it still not having internet. How to solve this?

Please note that timestamps are useless since you are on a mobile device where the clock might be changed by the user.

What would you suggest? I don't want to ask the user about conflict solving but implement some automation. (Just take the most current one)

Thanks

Upvotes: 1

Views: 108

Answers (3)

vkurchatkin
vkurchatkin

Reputation: 13570

Try http://www.couchbase.com/communities/couchbase-lite. It's an embedded NoSQL store for iOS and Android, which is able to sync with CouchDB and Couchbase Server.

Upvotes: 1

flo850
flo850

Reputation: 138

I beg to differ : how long ago is quite risky. For example some countries have a daylight saving time

I think you should look into ready to use solution like couchdb( and his sqlite cousin :pouchdb): you can make explicit or implicits synchronisation, and there's quite a work done for solving conflicts http://guide.couchdb.org/draft/conflicts.html

Upvotes: 1

samael
samael

Reputation: 2178

timestamp isn't useless, you just need to rethink how you use it. In this case the servers time is god. when the mobile device establishes contacts the server, the mobile can let the server know how long ago from now the data in question was created. Then once the information is transferred the server knows to set the time for that data as the current time on the server minus the amount of time that provided by the mobile.

So for example:

  • 8am your data updated directly on webapp - correct time
  • 9am data updated on mobile - (no network access + time not trusted)
  • 10am more data updated to webapp (currently 2 data entries on server)
  • 11am your mobile gets network access and contacts the server. Your mobile knows that the 9am data was 2 hours ago, so this is what it needs to tell the server. The server receives the data and now knows that it's 2 hours old. The server is able to persist the new information with the time stamp of: (current time on server - 2hours).

This way the time for the 9am data will be correct regardless of the time on the mobile device.

Upvotes: 4

Related Questions