How a Conflict Is Resolved When Offline Records Return

If the last write wins, the other device’s record is deleted. Lamport’s order records which change happened before which. The merge rule is set separately.

How a Conflict Is Resolved When Offline Records Return

If two devices change the same record while they are disconnected, both changes are valid when the link returns. Comparing their clocks deletes one of those valid changes. A wall clock drifts between devices. If one has fallen behind, its change looks "old" and is dropped.

Lamport wrote, in 1978, the order of events in a distributed system without tying it to a wall clock. The "happened before" relation holds when one event could have caused the other. A logical clock turns that relation into a number. The number also shows that two changes were made without knowledge of each other. Two changes made without knowledge of each other are a conflict. A conflict is not closed by letting the larger clock win.

The close comes from the meaning of the field. If a counter rose on both sides, the total is the combination of the two rises. If a text field changed on both sides, writing one over the other loses data. The record then keeps both versions and asks a person to choose. If the choice is not written down, the software silently keeps the last write. The loss does not appear in the log.

Identity is part of the conflict. The same job may have been opened on two devices with two local identities. The server reads them as two records. The local identity and the server identity are kept apart. The mapping is written on the first successful send.

In a FenergyTech app that keeps offline records, the merge rule for each field goes into the contract. If there is no rule, the field cannot be edited offline.

A wall clock closes the conflict on the wrong record. One tablet has fallen behind. Its record was made later, and its clock is smaller. "Last write wins" deletes that record. The "happened before" relation Lamport wrote in 1978 holds when one event could have caused the other. If two records were made without knowledge of each other, there is no relation. Without a relation, the larger clock does not pick the winner. The pick comes from the meaning of the field.

If a counter rose on both sides, the total is the combination of the two rises. If a text changed on both sides, one is not written over the other. The record keeps both versions and asks a person to choose. If the choice is not written down, the software silently keeps the later clock. The loss does not appear in the log.

The same job may have been opened on two devices under two local identities. The server reads them as two records. The local identity and the server identity stay apart. The mapping is written on the first successful send. Without the mapping, the merge joins the wrong pair.

Sources: L. Lamport, "Time, Clocks, and the Ordering of Events in a Distributed System", Communications of the ACM, vol. 21, no. 7, pp. 558–565, 1978.

Share:

Planning a similar project?

We can talk through how the topic in this article applies to your product.

More articles

Browse our other technical articles