Operational Transformation (OT) Protocol for Collaborative Working
- Dominant language
- Dart
- Stars
- 152
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
In order to sync a list of items between 2+ devices (_either belonging to the **same** person or when shared/collaborating with **another** person_) we need to have an efficient way of transmitting the _changes_ that have been made. We don't want to send the _whole_ list each time as it's both inefficient and error prone as conflicts can occur. The last thing we want is two people to be editing the _same_ item on a list and for one to overwrite the changes made by the other.
This is a well understood problem and has a name "Operational Transform".
Each operation that is performed is described by a set of keywords that can be sent between clients to keep them all in sync. see: https://en.wikipedia.org/wiki/Operational_transformation
For a quick (basic) introduction to how OT works, take a look at the [Quill.js](https://quilljs.com) rich text editor.
Quill uses the [Delta](https://quilljs.com/docs/delta) OT format to describe the changes that are made in an editor.
The **`delta`** is a List (Array) of "ops" that can be sent over the network to other connected clients and "replayed" to bring the two clients into sync.
While reading the Delta spec and researching how Quill.js works in https://github.com/dwyl/app/issues/275#issuecomment-640607181 we realised that Quill is designed for Text Editing _not_ for tasks. There is a feature request in their backlog: https://github.com/quilljs/quill/issues/759 but it's not yet been implemented. And that got us thinking:
+ What if we need to _extend_ Delta to do a lot more things, how do we do that?
+ Should we still use Delta even though we are going to _heavily_ modify it to include timestamps, `item.id` (_so we know which item was edited_), `person.id` (_to see who is editing what_) and some sort of checksum (e.g. [`CID`](https://github.com/dwyl/cid)) to avoid spoofing.
## Google/Apache Wave
Google/Apache Wave https://en.wikipedia.org/wiki/Apache_Wave was a software framework for real-time collaborative editing online. It was _way_ ahead of it's time and most people didn't "get" it.
Watch the Google Overview from 2009:
[](https://youtu.be/p6pgxLaDdQw)
https://youtu.be/p6pgxLaDdQw
All of the innovative features that were available in Google Wave were made possible by OT.
While Google Wave was discontinued in 2012 https://killedbygoogle.com 🙄
the underlying **collaborative editing** features are still available in Google Docs https://en.wikipedia.org/wiki/Google_Docs#Editing
11 years later, inlining "gadgets" in the rich UI is now being copied by **Microsoft Fluid**:
[](https://youtu.be/cy1Tyr93Sw4)
https://youtu.be/cy1Tyr93Sw4
The Google/Apache Wave (over [XMPP](https://en.wikipedia.org/wiki/XMPP)) **Spec** is still available:
https://svn.apache.org/repos/asf/incubator/wave/whitepapers/federation/wavespec.html
# Todo
+ [ ] Investigate the available OT formats and see which one can work for us.
+ [ ] The format we select (_or `create`_) needs to be extensible so that we can add features to our app and not be limited by the existing OT vocabulary.
I expect that reading the Google Wave Spec and researching other OT specs will take me around a day. I will leave comments on this thread with my progress.
Contributor guide
Assessment
This issue has not been assessed yet.