Rajan Rawal
Rajan Rawal

Reputation: 6317

Synchronize database data across webserver and multiple mobile devices

Whole scenario is considered using connectivity not available all time. And synch will happen all together when connectivity is available.

the android app I am developing is going up to the next phase. Earlier I had one way data push. i.e from mobile device to server. server has mysql data base. For that I made simple api with http request with json data to be sent on server.

User can have more than one smartphone devices ( For now andorid ). When data get synchronized all the mobile local data get pushed on server. Any server changes should also get reflected on mobile data. Two way synchronization across multiple devices.

I am considering following scenario. For mobile I am using sqllite db on android.

On Mobile 1 database, Any record can be : insert, update, delete 
On Mobile 2 database, Any record can be : insert, update, delete 
. 
. 
. 
On Mobile `N` database, Any record can be : insert, update, delete

On Server database, Any record can be : insert, update, delete

And in all these scenario, data should get synchronized across all device along with server. However when synch is performed it will be between that one mobile device and server, not all device at same time.

I have no idea regarding this. I want to know that what approach should I use? So that all data get at same state.

I am planning to develop api for this. Any advice will be helpful.

Upvotes: 3

Views: 2237

Answers (1)

AdamZ
AdamZ

Reputation: 2021

You need to implement some kind of messages preferably using JSON. Any device can send a message to insert, update or delete in database. Every device should receive all the messages and use them as a changelog.

The key concept is synchronisation between devices. For this simplest way is to use MQTT protocol with mosquitto server.

MQTT is a protocol for sending messages between multiple devices. Any client can send a message to MQTT server (called broker) and any other client may be guaranteed to receive all messages as soon as it restores it's connection.

Something like this is used in Facebook Messenger so You can have a discussion on multiple devices at the same time. If You send message to Your friend on one device it automatically pop up as send on all others on Your facebook account.

MQTT is quite simple and powerful to use. I believe it can save You a lot of time in developing Your app.

Check out http://mqtt.org/ and http://mosquitto.org/

Upvotes: 1

Related Questions