Operational Transformations as an algorithm for automatic conflict resolution

Anton Zagorskii
Jul 18, 2018 · 10 min read

1. Introduction

Automatic conflicts resolution algorithms in distributed systems with more than one leader nodes (In this article by leader node we mean a node which accepts data changing requests) is quite interesting research field. There are different approaches and algorithms in this area with their own trade-offs and in this article we will focus on Operational Transformation technology which is aimed to solve conflicts in collaborative editing applications like Google Docs or Etherpad.

1.1 First versions of Google Docs

First versions of Google Docs (as well as other similar applications) used a comparison of document versions. Imagine we have two clients — Alice and Bob and their documents are synchronized. When the server receives changes from Alice it calculates the diff between her version and its and tries to merge them. Then the server sends the merged version to Bob. If Bob has his own unsent changes he tries to merge received server’s version with his. And the process repeats.

1.2 Latest Google Docs versions

Latest Google Docs versions follow another approach — a document is stored as a sequence of operations and they are applied in order (by order here we mean a total order) instead of comparing versions of documents.

  • Delete text
  • Apply style

1.3 Example

Let Alice and Bob start from a synchronized document “LIFE 2017”.

2. Operational Transformation

2.1 Consistency models

Few consistency models have been developed to provide consistency for OT. Let’s consider one of them — CCI model.

2.2 OT Design

One of the OT design strategies is to split it into 3 parts:

  1. Transformation functions: responsible for performing actual transformations on the target operation according to the impact of the reference operation
  2. Properties and conditions: define the relationships between transformation control algorithms and functions, and serve as OT algorithm correctness requirement

2.3 Transformation functions

Transformation functions can be divided into two types:

  • Exclusion/Backward transformation: to transform operation Oa before Ob so that the effect of Ob is excluded (e.g. insertion after deletion)

3. Collaboration protocol in Google Docs

Let’s consider how Google Docs collaboration protocol works in more details.

  • All local changes which have not been sent to the server (Pending changes)
  • All local changes sent to the server but have not been acknowledged (Sent changes)
  • Current document state visible to the user
  • Log of all processed changes (Revision log)
  • State of the document on the time of last processed change

4. Etherpad

Let’s have a look at another collaborative editing application which uses OT technique — http://etherpad.org

  • p2 — length of the document after the change
  • c_i — definition if the document:
    if c_i — number or range of numbers then it means indices of retained character, or
    if c_i — character or string then it means insertion
  • “Hllo World” + (10 -> 14)[0, ‘e’, 1–9, “!!!”] = “Hello World!!!”
  • Insertions in B become insertions
  • Retain all retained characters in both A and B

Example

5. Critique of OT

  • All document changes must be saved in a set of operations
  • OT implementation could be a very complex task, quoting from wikipedia:
    Similarly, Joseph Gentle who is a former Google Wave engineer and an author of the Share.JS library wrote, “Unfortunately, implementing OT sucks. There’s a million algorithms with different tradeoffs, mostly trapped in academic papers. The algorithms are really hard and time consuming to implement correctly. […] Wave took 2 years to write and if we rewrote it today, it would take almost as long to write a second time.”

6. References

Coinmonks

Coinmonks is a non-profit Crypto educational publication.