Results 1 to 3 of 3

Thread: Bi-Directional Syncing for offline apps

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Vote Rating

    Default 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.

    I'm looking at a JavaScript HTML 5 solution for two reasons. Cross-platform (iPhone and Andriod) and the fact that this is a open source community project that does not fit well with the Apple SDK AppStore platform. 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.

    • An HTML5/JavaScript based Web application that runs offline (as an app you can install using the "Add to home screen" button).
    • 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.

    For further details this is a task management application that interfaces with a rails based application called Tracks which provides a REST API using standard CRUD operations (the usual). I want this JavaScript application to cache on the mobile device via the cache manifest and other offline tricks that WebKit and Apple iOS offers. I want the user to sync the data between the server and the mobile device so that the user can add new entires, organize models, and essentially manipulate the data on the mobile device while they are on an airplane with airplane mode then once network is back these changes can be sent to the 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?

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Munich (Germany)
    Vote Rating


    take a look at:!/...y.LocalStorage

    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

  3. #3
    Ext JS Premium Member
    Join Date
    Aug 2007
    Antwerp, Belgium
    Vote Rating


    Quote Originally Posted by tobiu View Post
    ... check if you are online ...
    Ha, if there was only a reliable way of doing that. navigator.onLine is a lie. There is no solution (native or web) that gives you a truthful answer whether you're online or not, aside from just trying to contact the server and seeing if you can reach it. And even that last one doesn't give the whole picture, because you don't know the bandwidth or latency of the connection (perhaps you're on GPRS at 4 KB / sec), and because in a moving vehicle connection quality changes every second.

    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.
    - 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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts