Ask HN: Mobile app that works offline and syncs data periodically

4 points by saurabhnanda ↗ HN
At our startup, our target market is increasingly conducting their business, on-the-go. Therefore, we have to augment our browser-based desktop app with a mobile app.

Therefore, I'm now evaluating what it would take to develop a mobile app that could work completely offline and sync transaction data periodically with the central server.

I've read briefly about Firebase, Parse, Usergrid, BaasBox, master-master replication, and the CAP theorem. As expected, I'm royally confused now!

We've already built out or backend using Postgres and RoR. Ideally I'd like to stick to it, especially Postgres, as we're dealing with financial transactions. We already have HTTP/JSON APIs to read/write data. We can also develop fine-grained APIs using Thrift, if required.

Now, my question is, is there a project/service/SDK out there which has already solved this data sync problem? What about conflict resolution when it comes to transaction data? I understand that this is like resolving merge conflicts in git, which basically requires human intervention, but is there an SDK that will reduce dev time for such scenarios? Can said SDK work with a custom backend API?

2 comments

[ 4.0 ms ] story [ 11.1 ms ] thread
"That could work completely offline and sync transaction data periodically with the central server."

From what I've gathered you want the app to sync data when possible but still work as it should when offline? There are several solutions in the space of this.

A simple solution would be to split or abstract the logic with handling the data versus the functionality of the mobile app itself. In which case you should not be tied down to specific backends.

Anything that works for mongodb or other databases you can usually find something that converts said backend to something working for postgres or whatever for server side.

As for mobile your data backend should be something lightweight and it may be beneficial to use something that is agnostic to mobile like html5. Key players for web data usually are Indexedb and somewhat basket.js : https://addyosmani.github.io/basket.js/ . As the web is usually the way of using what mobile apps are using for storage gathered from a look at angular.js in retrospect. And another popular database for mobile is couchdb.

Some of the other stuff you mentioned:

A more accurate terminology for what you may be looking for in the future for communicating with several distributed systems would be a CRDT key-value(for example; https://github.com/dominictarr/crdt ) if you want it to be purely distributed over many devices completely and provide the same updates to many devices. There is still a lot of on-going research in the area with Riak and Redis having somewhat successful uses in the box at the moment. A newer idea is something called SyncFree: https://github.com/SyncFree

As for resolving git transaction conflicting updates there is a solution that is being developed talked about here: http://the-paper-trail.org/blog/subverting-sinfonia/

A more json version for updates would be something along the lines of: https://github.com/Operational-Transformation

I have been looking for tools to solve the same problem for a while now.

Based on documentation, the most promising approach seems to be to use Couchbase Mobile/Lite in the app, Couchbase Server on the server, and link them up with their sync gateway: http://developer.couchbase.com/mobile/develop/guides/sync-ga...

It seems that this should make it possible to save data both on the client and server side, and leave sync and replication to the databases themselves.

Now, I haven't actually adopted it yet for two reasons:

* My server stack is built on top of Postgresql and Django, so I would need to either rip out Postgres and go all-in with Couchbase, or somehow sync between Postgres and Couchbase on the server, and

* Authentication, authorization and data access filtering has to be implemented as custom Javascript plugins in the sync gateway, so I would have to rewrite most of my server-side app logic. By default the clients have full write access to the server database...

But if you do give this a try, I would really like to hear about your experience.