How to Resolve Conflicts with Converging Conflicts?

In this post of resolving conflicts, there are few strategies to achieve conflict resolution methodically. There is an importance to understand a diverse range of solutions as this can aid with applying the correct strategy for the type of optimisations that the requirements imply.

The the solutions that will be write conflict solution that will be converging conflict resolution.

Converging towards a consistent state

A single leader database applies writes in a sequential order.

  • If there are several updates to a field the last writes determine the value of the field

🤨 Although…

In a multi-leader configuration there is no defined ordering of writes!

  • So it is not clear what the final value should be 😵‍💫

📃 In the Wiki example:

  • At leader 1 – the title is first updated to X and then Y
  • At leader 2 – the title is first updated to Y and then X

In the example above, neither order is more correct than the other.

  • 🤔 If each replica simply applied writes in the order the writes they were given
  • ❌ The database would end up in an inconsistent state
    • The final value would be Y at leader 1
    • The final value would be X at leader 2
  • This is not acceptable ✋
  • 👉 Every replication scheme must ensure data is the same in all replicas

The database must solve this in an converging way

  • Meaning, all replicas should output at the same final value when all changes have been replicated 🃏🃏

Solution: Converging conflict resolution

First method

  1. Give each write a unique ID such as:
    • Long random number
    • Timestamp
    • UUID
    • Hash of the key value
  2. Pick the write with the highest ID and throw away the other writes
    • If a timestamp is used this technique is called ‘last write wins’ (LWW)

❌ Although this solution is popular, it is susceptible to data loss.

Second method

  1. Give each replica a unique ID
  2. Let writes that originate from a higher number replica always take the priority over the writes that originate from lower number replica

❌ This method also incurs data loss.

Third method

  1. Merge the values together
  2. Order them alphabetically and then concatenate them
  3. In the Wiki example, this would look like – X / Y

Forth method

  1. Record the conflict in an eplixicit data structure that preserves all information
  2. Then write application code that resolves the conflict as some later point in time
    • Possibly by prompting the user?

To be continued…

There are more solutions to handle conflict resolution, in coming posts I will be covering:

  • Custom conflict resolution logic
  • Automatic conflict resolution

And if you have not read my most recent post in this series, there is the alternative approach on avoiding conflicts covered here.

5 thoughts on “How to Resolve Conflicts with Converging Conflicts?

Leave a comment