Abhinav
Abhinav

Reputation: 8168

Sync Mobile App and Web App without third party services

Currently building a hybrid app. using Ionic Framework with PHP for backend services

I am having a case where a user has got his profile in Web app and Mobile App as well.

If the user adds two stories as favourites (Its kind of a reading app) from his mobile app or Web app,how do I sync that?

Here are the scenarios:

1) User marks the stories favourites from web app and when I come online through mobile app, display it.

2) User marks the stories favourites from mobile app when he is offline(Now this will be stored in LocalDB). So again when he comes online sync with the server?

I know there are services like Firebase which provides syncing service.

But What If I would want to develop a Custom Syncing service on my own for my application? Is that an extremely complicated process?

If yes and it can be developed ,then how should I proceed ? A basic idea? What are the best practices that I should consider?

Any links would be appreciated?

Upvotes: 3

Views: 1328

Answers (2)

Nic Raboy
Nic Raboy

Reputation: 3153

I know some of the comments recommended CouchDB in combination with PouchDB. That is a much better solution than trying to implement your own synchronization service with MySQL.

However, since you're using Ionic Framework you can also use Couchbase. Take the following example application:

https://github.com/couchbaselabs/TodoLite-Ionic

If you chose this solution you would have three moving parts. You would be replacing MySQL with Couchbase Server and running the Couchbase Sync Gateway to orchestrate any data between the device and the server. You can still keep your PHP backend if you have a web version of your application as there is a PHP SDK for Couchbase.

Two write-ups on this can be found here:

http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-1 http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-2

In the long term, you're going to find NoSQL much more pleasant to work with when it comes to APIs and mobile than MySQL.

Upvotes: 1

Can be useful to write a POST method on the backend that receives the data from your local from the app and some user data (session, access tokens and other thing you considered neceasary). On the body for the request you include the data needed to be synced. The backend takes the body. Parse it and rreturn a result (http code) Based on that you can decide if the app should delete the local data or only mark it as synced on the local database

Upvotes: 0

Related Questions