The first thing you need to decide is a general policy on which side is considered “authoritative” in the event of conflicting changes.
Ie: suppose that record No. 125 will be changed on the server on January 5 at 10 pm, and the same record will be changed on one of the phones (call customer A) on January 5 at 11 pm. The last sync was January 3rd. Then the user connects again, for example, on January 8th.
Determining what needs to be changed is “easy” in the sense that both the client and the server know the date of the last synchronization, therefore everything that has been created or updated (see below to learn more about this), since the last synchronization must be consistent .
So, suppose that the only record changed is # 125. You either decide that one of the two automatically “wins” and overwrites the other, or you need to maintain the reconciliation phase when the user can decide which version (server or client) is correct, overwriting another.
This decision is extremely important, and you must weigh the "role" of customers. Especially if there is a potential conflict not only between the client and the server, but in case different clients can change the same record (s).
[Assuming that # 125 could be modified by the second client (Client B), it is likely that Client B, which has not yet synchronized, will provide another version of the same record, which makes the previous resolution of the conflict controversial]
Regarding the "created or updated" point above ... how can you correctly identify the record if it was created on one of the clients (if this makes sense in your problem area)? Suppose your application manages a list of business contacts. If Client A says that you have to add the newly created John Smith, and on the server there is John Smith created yesterday by client D ... you create two records because you cannot be sure that they are not different people? Do you also ask the user to come to terms with this conflict?
Do customers have a "property" of a subset of the data? That is, if Client B is configured as an "authority" on the data for Region No. 5, can Client A change / create records for Region No. 5 or not? (This will facilitate conflict resolution, but may not be feasible for your situation).
To summarize, the main problems are:
- How to determine the "identifier", given that individual clients could not access the server before creating a new record.
- In the previous situation, no matter how difficult the decision can lead to duplication of data, you must foresee how to periodically solve them and how to inform customers that what they consider to be “Record No. 675” has actually been merged with / replaced recorded # 543
- Decide whether conflicts will be resolved using fiat (for example, "the server version always trumps the client if the first has been updated since the last synchronization") or manually [/ li>
- In the case of fiat, especially if you decide that the client takes precedence, you should also take care of how to handle other, not yet synchronized clients, which may have a few more changes.
- The preceding elements do not take into account the granularity of your data (to simplify the description). It is enough to say that instead of reasoning at the “Record” level, as in my example, you may find it more suitable for recording changes at the field level. Or to work on a set of records (for example, Recording a person + Recording an address + Recording contacts) at the same time, considering their combination as a kind of “Meta-record”.
Bibliography:
More about this, of course, about Wikipedia .
A simple synchronization algorithm by Vdirsyncer
OBJC Data Sync Article
SyncML®: Synchronizing and Managing Your Mobile Data (Safari O'Reilly Book)
Unrestored Replicated Data Types
Optimistic Replication YASUSHI SAITO (HP Laboratories) and MARC SHAPIRO (Microsoft Research Ltd.) - ACM Computing Surveys, Vol. V, No. N, 3 2005.
Alexander Traud, Jürgen Nagler-Elaine, Frank Kargl and Michael Weber. Synchronize cyclic data by reusing SyncML. Proceedings of the Ninth International Conference on Mobile Data Management (MDM '08). IEEE Computer Society, Washington, USA, 165-172. DOI = 10.1109 / MDM.2008.10 http://dx.doi.org/10.1109/MDM.2008.10
Lam, F., Lam, N., and Wong, R. 2002. Effective synchronization for XML mobile data. Proceedings of the Eleventh International Conference on Information and Knowledge Management (McLean, Virginia, USA, November 4–09, 2002). CIKM '02. ACM, New York, NY, 153-160. DOI = http://doi.acm.org/10.1145/584792.584820
Cunha, PR and Maibaum, TS 1981. Resource & equil; abstract data type + synchronization - methodology for message-oriented programming. In the materials of the 5th international conference on software development (San Diego, California, USA, March 09 - 12, 1981). International Conference on Software Development. IEEE Press, Piscataway, NJ, 263-272.
(The last three are from the ACM digital library, I don’t know if you are a member or you can get them through other channels).
From the Dr.Dobbs website :
- Creating Applications with SQL Server CE and SQL RDA by Bill Wagner May 19, 2004 (Recommendations for Developing an Application for Desktop and Mobile PC - Windows / .NET)
From arxiv.org:
- Non-Conflicted Replicated JSON Datatype - This document describes the implementation of JSON CRDT (Replicated Conflict Types - CRDT) - a family of data structures that support simultaneous modification and ensure the convergence of such concurrent updates).