Challenges with Data Synchronization
Data synchronization technology is a very important part of enabling offline usage of data, but it also presents some challenges that need to be solved in order to provide a sound solution. The following section focuses on the central master topology, since it is currently the most widely used.
The main challenges are:
- Conflicting updates
- Conflict detection
- Conflict resolution
Another challenge with data synchronization is the need to agree on a common content format for data exchanges. For PIM data, SyncML requires the support of specific content formats to ensure successful synchronizations.
In Data Synchronization, where copies of the same data reside on more than one device, it is very likely that the same entry is manipulated on more than one device.
Consider a datastore with customer records, containing the customer's name, address (street and city), and data about recent orders. This data is centrally stored in the corporation's mainframe computer. The salesmen who visit customers during the day synchronize their PDAs with this corporate datastore every morning and every evening.
During his visit at a customer, the salesman changed the fax number for the customer "Smith" to "12345". The same day, the customer relations department received a letter from Mr. Smith notifying them that his fax number has changed. The customer relations agent updated Mr. Smith's record, but unfortunately made a typo while entering the number and updated the entry with "92345".
Two conflicting updates to the same record have been made since last time the salesman synchronized the customer datastore. It is now up to the synchronization server to first detect the conflict and then resolve it.
If the synchronization server could not detect the conflict, it would send the update it had received from the customer relationship department to the salesman's PDA and would also update the master datastore with the update the salesman made during the day. As a result, the content of the two copies would not contain the same datathe master datastore would have the fax number "12345", and the salesman's PDA would contain "92345". This problem would probably remain, undetected and uncorrected, until somebody updated the same object again. The problem described below is illustrated in Figure 18.
The update conflict described above is known as a write-write conflict: The same field is updated in the same time period in two different copies of the datastore. Other update conflicts include read-write conflict and constraint violations. They are explained later in this chapter.
Figure 18 Synchronization without conflict detection
For example, examine the following scenario: During the day a salesman is entering a new order for the customer with the name "Smith" and changes his fax number from "98765" to "12345". At the same time, the corporate marketing department is creating a list of all customers' fax numbers for a mass mailing. The salesman hasn't synchronized his PDA yet, and therefore the central datastore's entry for the fax number of the customer "Smith" still contains "98765", where "12345" is the correct value. This situation is called a stale read, where one retrieves an entry from one copy of the datastore that is not up to date because a change was made to another copy of the same datastore and wasn't propagated to all other copies of the datastore. Figure 19 illustrates this situation.
Figure 19 Stale reads
In the case of a read-write conflict, the update to a data field is made based on the value of another field in the datastore. While making this update in one copy of the datastore, the field that determined the decision to update the other field was changed in another copy of the datastore. Therefore the update is made based on a stale read. Detecting these conflicts is especially important for Relational Databases. PIM systems rarely have these conflicts.
One possible example of a conflict based on a constraint violation is where a certain field in the datastore is constrained to accept only values
between "1" and "10". Now this constraint is changed such that only values between "1" and "5" are acceptable. In another copy of the datastore, somebody enters a value of "8" into the field with this constraint. During the next synchronization the synchronization server has to detect this conflict if the datastore is to be kept consistent.
One possible way of preventing conflicting updates (especially read-write conflicts) is to obtain exclusive access to an object before updating it. In the central master scenario this would require the device to contact the central master and request exclusive access. This might be possible in intranet scenarios, but is not an option with mobile devices. Mobile devices might be in areas that currently have no network coverage. Also, setting up a wireless network connection, for example via GSM, takes a few seconds and can be quite expensive (especially when roaming internationally). Therefore getting exclusive access to the object before updating it is not a practical alternative. Thus, a synchronization server must be capable of detecting and resolving conflicts.
The conflicts mentioned above all belong to a category of conflicts called mechanical conflicts, since there have been concurrent modifications to the same record. It is also possible, however, for a user to enter a meeting with a customer from 8:00 to 10:00 in the morning while his secretary blocks the 9:00 to 10:30 slot for a meeting between the user and his manager. From a synchronization technology point of view, there is no conflict. Both records were newly added distinct calendar entries. But the user now has to attend two meetings from 9:00 to 10:00, which is a semantic conflict that the user needs to solve. The calendar application can in this case support the user by detecting the conflict and informing the user about this.
Conflict detection is important in order to keep different datastores in "sync," meaning keeping them consistent.
One important prerequisite of being able to synchronize data is the ability to uniquely identify each record in the datastore. Relational Databases have primary keys that serve this very purpose. In other types of datastores, such as PIMs for example, UIDs (unique identifiers) are used. The UIDs in the datastore on the central master are usually called GUIDs (globally unique identifiers; possibly only unique in the scope of that one datastore). Each copy of the datastore on a client has
its own UIDs to identify the records, which are called LUIDs (locally unique identifiers).
The central master maintains a datastore to store the LUID of each record for every client that synchronized a given datastore. While synchronizing, the central master uses this LUID to tell the client which record to modify.
A synchronization session usually starts with the client sending a list of changed records since the last synchronization for a particular datastore to the server. Next, the central master then generates a list of all modifications that occurred during in the same time period. To detect possible conflicts, the server then compares the two lists and identifies every LUID/GUID combination that exists in both of the lists as a conflict, as shown in Figure 110.
Figure 110 Identifying an update conflict
Conflict resolution is the action that the server must take after a conflict has been detected.
There exists a wide variety of methods a server can use to resolve conflicts. The easiest way for the server is to duplicate the entries and to mark them as conflicts. This strategy does not lose any data, but puts the burden of resolving the conflicts on the user (who has to manually choose the correct record or merge the two records).
The next possibility is for the server to identify one of the two conflicting records as the winner and delete the other one. The decision can be based on user preferences, such as:
Updates made on the client always win.
Updates made on the server always win.
The latest change wins.
Basing the decision on where the change was made is a pretty simple method to implement. Making the decision based on which one of the two conflicting updates was the latest one is more complicated. First, this requires the datastores to record the time when the change was made. This is often impossible, especially with mobile devices, like mobile phones, or PDAs, like the Palm Pilot™. For this to work, the system time needs to be synchronized across all the devices involved, or a scheme must be set up to address time-drift.
The third method to resolve conflicts is to merge the two conflicting records into one new one. This could be done in cases where complete records are synchronized, for example an address book record containing name, street, city, and phone number. Additionally, this requires the synchronization server to understand the structure of the data that is synchronized and to be able to identify the field within that structure that was changed. This is not possible if the records contain only single fields that are to be synchronized, and the synchronization server cannot interpret the data in the field.
Resolving conflicts with PIM data is relatively easy. It is more complex with Relational Databases, which usually have relationships between different records that need to be honored during conflict resolution.