Data sync between mobile app and cloud
Well I am building an app for both iOS and Android and both apps need to be in sync with MySQL cloud DB. Both apps work offline, so I need all the insert and update functionality. Delete will probably not be used, but still I would like to know.
Well, I'm looking here for a solution or ideas or algorithms to do for this.
I saved CreateOn and LastSync as a timestamp column for each table.
Now the problem is, should I always check all rows and all columns every time?
I think I should keep the ModifiedOn column in all tables and check that with LastSync for each device ID. What do you suggest?
source to share
This may not be the answer you are looking for, but in a project I am working on, we are using Azure Mobile Services. There are Android and iOS SDKs where they have implemented synchronization between a standalone database and Azure (as with Git, you can call push and pull methods).
There are some limitations (TableStorage is MSSQL limited storage) but you should check that.
source to share
I know this about two years overdue, but I did the same (Android app that syncs with web api and postgresql)
What I am doing so far (still researching if this is the best way how I found this question) is that I keep the last_update field with a timestamp when the data was last_updated and the modified field with a boolean whether the data has been changed (by user action on the device)
So when I do sync:
- First I copy the database to the backup (in case of problem)
- I am posting all lines marked as modified (server handles conflicts)
- then remove them
- after that i find the value max (last_update),
- I subtract one minute from it
- Then query for all rows that have been updated after this value (this will also include the data I submitted, because there is no way, unless there is a problem, that the row is set to change with last_update before the last unmodified row)
This can cause some duplicate data to be carried over (especially if you often make a lot of changes), but in my case this is a rare occurrence.
source to share