-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Operational Transformation (OT) Protocol for Collaborative Working #276
Comments
@LuchoTurtle this is how we are going to store & sync actions between devices/people in our App. ♻️ |
I know this is more "low-level" than what was mentioned on dwyl/technology-stack#106. After all, we are going to make use of libraries (perhaps https://github.com/izelnakri/paper_trail ?) that use OT "under the hood". Here's a quick rundown of what I captured. The Operational part of OTThe first part is operation. The basic philosophy is that you can have a document and it can be translated into a series of functions - operation. For example, here are two examples of operations: Operation A Operation B
It's important because once we have this rule, we can combine operations together. The Transformation part of OTPerhaps the most interesting part of OT. What Google uses in Wave and Google Docs seems to be the following formula. Looking at this is hard to understand. To see this graphically makes much more sense. Imagine if we start from a starting state and two users are changing a document. The document has the word If we merely applied each operation of each user after the other, we would get a result that is not valid. This is where the formula comes in handy. We are able, from This a simple way of explaining what's going on. How does Google implement this?So this is how Google does it. They try to minimize server usage, so they basically push all the work onto the client side/browser. Let's give an example. This is taken from https://www.youtube.com/watch?v=u2_yccaHbQk&ab_channel=CocoaheadsTaipei. Imagine if we have three browsers and each one is working on a document and they all make a change at the same time. On the Google server, it prioritizes one operation. Let's imagine it prioritizes operation After logging this operation, it will send this information to all the browsers. So browser A knows his operation was taken by the server and knows it's in sync. The other browsers B and C will work on applying that change on the client-side. Now Google server decides to continue and add operation Browser B will merge the operation sent from the server. And browser B is now in sync. So Google Server just creates the order of the operations and updates all the clients with the order of the operations. On the other hand, the client-side only sends one instruction at a time and receives back the operation it sent to the server - it knows that it's time to converge. This is a simplistic view of this. This is the type of versioning that occurs in real-time document collaboration and can be opted for other use-cases. Why did Google use a client/server picture?By their own words, they purposely use this because it allows them to scour a large number of clients without complicating the system. By having a single source of truth (server), if users crash, they know where to fetch the timeline of actions and stay consistent with other clients. By forcing the client to wait for the server to acknowledge, it allows the server to keep a single history of operations without having to keep mirror of the client state for each client that is connected to it. This is much better for scalability. TakeawaysOf course, this is much more complex when it is applied in real-life scenarios and by Google. But having this simplistic view helps me understand how the inner workings...work! There are many libraries that allow doing OT. As it was pointed out in this issue, Quill uses Delta to OT in their live-editor. It's great having this understanding because personally, I didn't know how Google Docs made it possible. 😄 |
Great that you've gone on a journey of discovery/learning. thank you for capturing it. 👌 |
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 rich text editor.
Quill uses the 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 #275 (comment) we realised that Quill is designed for Text Editing not for tasks. There is a feature request in their backlog: slab/quill#759 but it's not yet been implemented. And that got us thinking:
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
) 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
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
The Google/Apache Wave (over XMPP) Spec is still available:
https://svn.apache.org/repos/asf/incubator/wave/whitepapers/federation/wavespec.html
Todo
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.
The text was updated successfully, but these errors were encountered: