Etherpad and Easysync Technical Manual: Appjet, Inc., With Modifications by The Etherpad Foundation March 26, 2011
Etherpad and Easysync Technical Manual: Appjet, Inc., With Modifications by The Etherpad Foundation March 26, 2011
Contents
1 Documents 2
2 Changesets 2
3 Changeset representation 2
4 Constraints on Changesets 2
5 Notation 3
6 Composition of Changesets 3
7 Changeset Merging 3
8 Follows 4
9 System Overview 5
10 Client State 5
11 Client Operations 5
11.1 New local typing . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
11.2 Submitting changesets to server . . . . . . . . . . . . . . . . . . . 6
11.3 Hear ACK from server . . . . . . . . . . . . . . . . . . . . . . . . 6
11.4 Hear about another client’s changeset . . . . . . . . . . . . . . . 6
11.5 Connect to server . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
12 Server Overview 7
13 Server State 7
1
1 Documents
• A document is a list of characters, or a string.
• A document can also be represented as a list of changesets.
2 Changesets
• A changeset represents a change to a document.
• A changeset can be applied to a document to produce a new document.
• When a document is represented as a list of changesets, it is assumed that
the first changeset applies to the empty document, [].
3 Changeset representation
(` → `0 )[c1 , c2 , c3 , ...]
where
4 Constraints on Changesets
• Changesets are canonical and therefor comparable. When represented in
computer memory, we always use the same representation for the same
changeset. If the memory representation of two changesets differ, they
must be different changesets.
• Changesets are compact. Thus, if there are two ways to represent a change-
set in computer memory, then we always use the representation that takes
up the fewest bytes.
2
5 Notation
• We use the algebraic multiplication notation to represent changeset appli-
cation.
6 Composition of Changesets
For any two changesets A, B such that
A = (n1 → n2 )[· · ·]
A = (n2 → n3 )[· · ·]
it is clear that there is a third changeset C = (n1 → n3 )[· · ·] such that applying
C to a document X yeilds the same resulting document as does applying A and
then B. In this case, we write AB = C.
Given the representation from Section 3, it is straightforward to compute
the composition of two changesets.
7 Changeset Merging
Now we come to realtime document editing. Suppose two different users make
two different changes to the same document at the same time. It is impossible
to compose these changes. For example, if we have the document X of length
n, we may have A = (n → na )[. . . na characters], B = (n → nb )[. . . nb characters]
where n 6= na 6= nb .
It is impossible to compute (XA)B because B can only be applied to a
document of length n, and (XA) has length na . Similarly, A cannot be appliet
to (XB) because (XB) has length nb .
This is where merging comes in. Merging takes two changesets that apply
to the same initial document (and that cannot be composed), and computes a
single new changeset that presevers the intent of both changes. The merge of
A and B is written as m(A, B). For the Etherpad system to work, we require
that m(A, B) = m(B, A).
3
Aside from what we have said so far about merging, there aremany different
implementations that will lead to a workable system. We have created one
implementation for text that has the following constraints.
8 Follows
When users A and B have the same document X on their screen, and they
proceed to make respective changesets A and B, it is no use to compute m(A, B),
because m(A, B) applies to document X, but the users are already looking at
document XA and XB. What we really want is to compute B 0 and A0 such
that
XAB 0 = XBA0 = Xm(A, B)
“Following” computes these B 0 and A0 changesets. The definition of the
“follow” function f is such that Af (A, B) = Bf (B, A) = m(A, B) = m(B, A).
When we computer f (A, B).
4
9 System Overview
There is a server that holds the current state of a document. Clients (users) can
connect to the server from their web browsers. The clients and server maintain
state and can send messages to one another in real-time, but because we are in
a web browser scenario, clients cannot send each other messages directly, and
must go through the server always. (This may distinguish from prior art?)
The other critical design feature of the system is that A client must always
be able to edit their local copy of the document, so the user is never blocked from
typing because of waiting to to send or receive data.
10 Client State
At any moment in time, a client maintains its state in the form of 3 changesets.
The client document looks like A · X · Y , where
A is the latest server version, the composition of all changesets committed
to the server, from this client or from others, that the server has informed this
client about. Initially A = (0 → N )[< initial document text >].
X is the composition of all changesets this client has submitted to the server
but has not heard back about yet. Initially X = (N → N )[0, 1, 2, . . . , N − 1], in
other words, the identity, henceforth denoted IN .
Y is the composition of all changesets this client has made but has not yet
submitted to the server yet. Initially Y = (N → N )[0, 1, 2, . . . , N − 1].
11 Client Operations
A client can do 5 things.
5
11.1 New local typing
When a user makes an edit E to the document, the client computes the com-
position (Y · E) and updates its local state, i.e. Y ← Y · E. I.e., if Y is the
variable holding local unsubmitted changes, it will be assigned the new value
(Y · E).
1. Send Y to server,
2. X ← Y
3. Y ← IN (the identity).
1. Compute A0 = AB
2. Compute X 0 = f (B, X)
3. Compute Y 0 = f (f (X, B), Y )
4. Compute D = f (Y, f (X, B))
5. Assign A ← A0 , X ← X 0 , Y ← Y 0 .
6. Apply D to the current view of the document displayed on the user’s
screen.
6
Proof that AXY = V ⇒ A0 X0 Y0 = VD. Substituting A0 X 0 Y 0 = (AB)(f (B, X))(f (f (X, B), Y )),
we recall that merges are commutative. So for any two changesets P and Q,
As claimed.
A ← HEADTEXT
X ← IN
Y ← IN
12 Server Overview
Like the client(s), the server has state and performs operations. Operations are
only performed in response to messages from clients.
13 Server State
The server maintains a document as an ordered list of revision records. A
revision record is a data structure that contains a changeset and authorship
information.
RevisionRecord = {
ChangeSet,
Source (unique ID),
Revision Number (consecutive order, starting at 0)
}
7
For efficiency, the server may also store a variable called HEADTEXT, which
is the composition of all changesets in the list of revision records. This is an
optimization, because clearly this can be computed from the set of revision
records.
1. Notes that this change applies to revision number rc (the client’s latest
revision).
2. Creates a new changeset C 0 that is relative to the server’s most recent revi-
sion number, which we call rH (H for HEAD). C 0 can be computed using
follows (Section 8). Remember that the server has a series of changesets,
8
Additional topics
(a) Optimizations (strips, more caching, etc.)
(b) Pseudocode for composition, merge, and follow
(c) How authorship information is used to color-code the document based
on who typed what
(d) How persistent connections are maintained between client and server