How to create online offline database together

been a while here actually guys!

I actually need help on a project am working on. what I want to do is have my application use an sql database offline and also have an online database, something like Google mail, you know the contact backup in Google that works offline, you save a contact and it automatically updates it when you are connected to the internet. just something exactly like that. I don’t know if am explanatory enough with this anyways but just something that works offline and can always migrate changes to the online database when connected.

I really don’t know how or where to start from and I really hope to get my way around here. thanks in advance

Hey @meshelleva4815 thanks for your question, sorry for the delay – I recently had a baby and I’ve been a little busy!

What you’re describing is an online/offline sync. There are a lot of complications with doing this – for example, can your app be run in multiple different places? If so, you need sync to work in two directions (from the server back to the client) rather than in one way. This also introduces the possibility of conflict.

Normally what you would do is –

  1. When starting the client should (try and…) sync the latest complete state with the remote server. This can be done by retrieve the full db (if it is small), or by retrieving the sequence of operations since our last connect.
  2. Once synced, the client should record it’s operations. For a database this can be a series of database operations (update/insert) etc. along with time (order) that they occurred.
  3. If connected, these can be sent to the server as they happen, or batched. If disconnected, the client should keep a log of them, to send when the reconnection occurs.

If you have conflicts – e.g. two separate clients have made conflicting changes, such as edited a field to different values – you’ll need some way to resolve this. Usually you would ask the user.

Hope that’s enough to get started?