A
A
adrianovalexey2014-08-19 16:33:50
iOS
adrianovalexey, 2014-08-19 16:33:50

How to organize client-server data synchronization for a mobile ios application?

There is a client and a server.
Now everyone stores their data, which is entered separately on the client and separately on the server.
Data can be created/modified/deleted on the client and on the server.
Changes can (in the target model) be made both on the client and on the server (from under one account, or by the administrator).
It is necessary to describe how to synchronize this data correctly.
To better describe what is required, let's take the Instagram application as an example.
I took a photo on instagram - it is visible on me, then on the server and on my friends.
Someone wrote a comment through the web version and it was reflected in me and my friends.
Someone liked at home - and again everything was updated along the chain - the user who liked it, the server, me and friends.
I deleted my comment from someone and it was lost from everyone who could see it.
How to implement such a synchronization scheme?
What is needed for this?
Share your practice and work cases.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Push Pull, 2014-08-19
@deadbyelpy

We do it quite simply. The local structure stores two identifiers, one is completely local, the other is the id that came from the server after creation.
The mechanism is this: have you done something, is there an Internet connection?
YES - sending to the server - received a successful response?
yes - added to the local database with the id that came from the server.
no - we write what the error is in the log, we apologize to the user (although the scheme is different, usually everything is ok, and not ok only if the server crashed) NO - we write to the local database, a network connection appears
with an empty server ID - we send local objects in portions ( if they were not deleted before the advent of the Internet) to obtain the required server ID
- we request a list of those deleted from the server (maybe something was deleted under this account on another device) we delete local objects
UPD: maybe someone will not guess right away, you never know. As soon as the server receives the data, it reports on the socket to all users who are online and are in some way related to the user's content that it was made

F
FoxInSox, 2014-08-19
@FoxInSox

You have only two synchronization methods:
- http request sent by the client to download/send data;
- PUSH notification that the server sends to the client;
Example:
1. Client A took a photo.
2. Client A sent a photo to the server.
3. The server received a photo
4. The server sent PUSH notifications to clients B and C with the information "there is a new photo from client A"
5. Clients B and C received notifications.
5.1 If the user (person) is in the photo feed, then the client makes a request to the server, uploads the photo and displays it.
5.2 If the user is, for example, on the settings screen, then the client displays a notification (toast) "there is a new photo from client A"

I
ivanzoid, 2014-08-21
@ivanzoid

You can try CouchBase Lite couchbase.com/mobile . I myself have not yet tried it in real projects, I just look closely. And it seems to suit your task well.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question