20 Jun 2012 4:58 AM #1
Bi-Directional Syncing for offline apps
Bi-Directional Syncing for offline apps
I'm at a loss which is why I'm reaching out to the community. I have been trying to find the best framework stack for a project of mine and have found no success at all. I find it even more frustrating that the web community at large has no libraries or example code on how to complete this obvious solution. Most forums just leave the answer as an exercise for the student.
I have a Rails based REST application. It has it's HTML output and it's XML REST API and a budding community. However the Mobile version of it's HTML have one glaring problem. It requires online access since it is a web-page. The offline solutions that describe Sencha Touch are nothing but a way to cache the data from a web site for offline viewing and don't offer any solutions for offline data manipulation. The application I would build is a very client side dependent as the data being manipulated is rather complex hence the interest in a web application framework not at mobile version of a web site.
Sencha.io seems to be a in-house solution to data synchronization between Sencha application (iPhone to iPad to Android) and is not a library to handle communications with an already established REST service running on your own web server.
That being said I'd like to describe what I want to accomplish in hopes someone has done something like this before and be willing to offer help.
- Have the ability to convert to a native app in the future is desired.
- Designed for the iPhone and Android phone platform (iPad and tablet would be nice too)
- Ability to download the data via a REST API (xml or json)
- Manipulate that data offline
- Once online sync that data back to the server and update from changes from that server.
There is not a multi user environment for the data as each record is only used by it's assign user (no sharing of data between users) so multiuser conflicts are not a problem. However it is very possible and likely that a user might make a change on the mobile device and forget to sync before using the web interface to make changes and this kind of conflict would need some resolution (Maybe latest transactions clobber older ones?)
So for the only pre-build solutions I have found are on the backbone.js world called backbone.offline which has brought me to think doing this in backbone instead of Sencha Touch a viable option. I have also been very unsuccessful finding good algorithm documentation on how one could implement their own code to do this.
My question is has anything like this been done using Sencha / ExtJS? If not is there any recommendations?
20 Jun 2012 5:10 AM #2
take a look at:
you can dynamically exchange the proxy of a model / store.
check if you are online, in cause you are not switch to localStorage, save changes there and push them to your backend when you get online again.Best regards
Tobias Uhlig, Solutions Engineer
S-CIRCLES Social Network Engine
20 Jun 2012 5:41 AM #3
What I do to handle sync is robust handling of timeout errors combined with user-driven synchronization. I'm assuming that when the user presses "synchronize" they have a pretty good idea about their connectivity.
As far as handling conflicts, you have these solutions:
- Optimistic conflict handling: store a hash of the downloaded data. If at synchronization time the data on the server has changed, refuse to synchronize (first to commit wins). This solution is best suited when conflicts are rare. http://en.wikipedia.org/wiki/Optimis...rrency_control
- Locking: when you take something offline, take a lock on it. You have to worry about users walking away halfway through (lock stealing needs to be possible). This is an extension of optimistic conflict handling that adds a roadblock to making a conflicting change. This solution is best when conflicts are operationally forbidden but technically possible.
- Merging: merge the data of both commits in some way, e.g. last field written overwrites earlier fields. This solution is best if you have a clear way to merge without losing data (which is almost never the case).
- Operational Transformation: extending the editing logic into the sync logic so that conflicts become impossible. Google docs does this, but the algorithm is not easy to understand. http://en.wikipedia.org/wiki/Operational_transformation