Scrivio Interview library
InternalsIntermediate7 min read · updated 13 November 2026

Two people edit the same spot in a shared document at the same moment: one inserts 'cat' at position 10 while the other deletes characters 8 to 12. Applied naively in different orders, their two copies of the document end up different.

How do operational transformation and sequence CRDTs each make both copies converge, and what does each approach cost in a real text editor?

Operational transformation rewrites an incoming operation against the concurrent operations already applied, for example moving an insert that falls inside a deleted range to the start of that range, so both copies end with the same text; with a central server that fixes one order, clients only transform against the server's sequence, which keeps it manageable. Sequence CRDTs give every character a unique, ordered identifier and make inserts refer to neighbouring identifiers instead of numeric positions, so concurrent edits merge in any order to the same result. OT costs correctness effort and a central server; CRDTs cost memory for per-character metadata and tombstones, careful handling of interleaving, and work to clean tombstones up.

Why this question is asked

Every real-time editor has to solve the same problem, and the two families of solutions shape everything else: whether the product needs a central server, whether it can work offline, and how much memory a document uses. Interviewers ask this to see whether we understand why positions break under concurrency and what each fix really costs, not just the acronyms. In this answer, we will recap what convergence means, reproduce the divergence with concrete text, fix it with operational transformation, see why OT is hard without a server, fix it again with a sequence CRDT, and compare the costs.

1A Quick Recap: Replicas and Convergence

Each editor holds its own copy of the document, called a replica, and applies its own edits immediately so typing feels instant. Edits from others arrive later. Two edits are concurrent when neither author had seen the other's edit when making their own. The system must guarantee convergence, meaning every replica ends with the same text once all edits have arrived, and it should also preserve intention, meaning the result looks like what each person meant.

The trouble is that edits are usually expressed with numeric positions. Position 10 means the tenth character in the author's copy at that moment. Once someone else inserts or deletes earlier in the text, position 10 refers to a different character.

2Reproducing the Divergence

Take the document 0123456789ABCDEF. Ann inserts cat at position 10, just before A. At the same moment Bob deletes positions 8 to 11, the four characters 89AB. Each applies their own edit first and the other's second, using the positions exactly as sent.

Java
start: "0123456789ABCDEF"
Ann: insert(10, "cat") Bob: delete(8, 4) // concurrent
Ann's copy: insert -> "0123456789catABCDEF"
delete(8, 4) -> removes "89ca" -> "01234567tABCDEF"
Bob's copy: delete -> "01234567CDEF"
insert(10, "cat") -> "01234567CDcatEF"
// Ann: "01234567tABCDEF" Bob: "01234567CDcatEF" diverged

Notice that both copies are wrong in different ways. In Ann's copy, Bob's delete removed half of her new word and missed AB. In Bob's copy, Ann's word landed in the middle of unrelated text. Both fixes below aim for the same sensible result: 01234567catCDEF, with Bob's four characters gone and Ann's word kept where she put it.

3Operational Transformation

Operational transformation, or OT, keeps numeric positions but rewrites an incoming operation to account for concurrent operations already applied. A transform function takes two concurrent operations and returns a version of the second that has the same effect after the first. For insert against delete, the rules are short: an insert after the deleted range shifts left by the deleted length, an insert before it stays, and an insert inside it moves to the start of the range. For delete against insert, a delete range that contains the insert point is split in two so the new text survives.

Java
// Ann receives Bob's delete(8, 4), transformed against her insert(10, "cat"):
// the insert point 10 lies inside 8..11, so the delete splits around "cat"
// -> delete(13, 2) then delete(8, 2) on "0123456789catABCDEF" (highest first)
// result: "01234567catCDEF"
// Bob receives Ann's insert(10, "cat"), transformed against his delete(8, 4):
// 10 lies inside the deleted range -> moves to its start, 8
// insert(8, "cat") on "01234567CDEF"
// result: "01234567catCDEF" // converged

Real systems add a central server, as in Google Docs-style designs built on the Jupiter approach. The server applies operations in one order and assigns revision numbers. A client sends an operation with its base revision, the server transforms it against every operation accepted since that revision, and clients transform incoming server operations against their own pending ones. Each client only reconciles against one sequence, the server's, which keeps the number of cases small.

4Why OT Is Hard Without a Server

Without a central order, operations can arrive at three or more replicas in many different orders, and the transform functions must then satisfy stronger mathematical properties, often called TP1 and TP2, so that every path through the transforms reaches the same result. Several published OT algorithms were later shown to violate these properties in corner cases. On top of that, a rich editor has many operation types: insert, delete, split paragraph, apply bold to a range, change a list, insert a table row. The number of transform pairs grows with the square of the operation types, and each pair has subtle cases. That is why production OT systems almost always keep a central server.

5Sequence CRDTs: Identifiers Instead of Positions

A CRDT, a conflict-free replicated data type, is a data structure designed so that replicas can apply the same set of operations in any order and still reach the same state. A sequence CRDT for text gives every character a unique identifier when it is inserted, typically the inserting replica's id plus a counter, such as (ann, 17). Characters are ordered by these identifiers and their neighbours, not by numbers that shift. An insert says put cat after the character with id (bob, 9). A delete says mark the character with id (bob, 8) as deleted. Deleted characters stay in the structure as tombstones, hidden from the user, so later inserts that refer to them can still find their place.

Java
// each character: (id, char, deleted)
// ... (b,8)'8' (b,9)'9' (b,10)'A' (b,11)'B' (b,12)'C' ...
Ann: insert after (b,9): (a,1)'c' (a,2)'a' (a,3)'t'
Bob: mark deleted (b,8) (b,9) (b,10) (b,11)
// applied in either order:
// ... (b,8)x (b,9)x (a,1)'c' (a,2)'a' (a,3)'t' (b,10)x (b,11)x (b,12)'C' ...
// visible text: "01234567catCDEF" // same on both replicas

So nothing needs transforming: the insert refers to a character that still exists, even if it is now a tombstone, and the merge rules fix a single order for concurrent inserts at the same spot. Well-known designs include RGA, YATA (used by Yjs), the algorithm behind Automerge, and newer ones such as Fugue.

6What Each Approach Costs

CRDTs move the cost from logic to data. Every character carries an identifier, so a naive implementation can use tens of bytes per character. Tombstones keep deleted text in memory, and they can only be removed once every replica has seen the deletion, which is hard to know when replicas may be offline for weeks. Two people typing at the same spot can see their letters interleaved, for example ccaatt instead of catcat, unless the algorithm is designed against it, which is what Fugue and careful YATA rules address. Modern libraries compress runs of characters typed in sequence into one entry, which brings memory down to a small multiple of the text size.

OT keeps the document compact and the metadata small, but it requires a central server and a lot of careful work for every new operation type.

Choosing between OT and a sequence CRDT
AspectServer-ordered OTSequence CRDT
Needs a central serveryes, it fixes the orderno, any order merges
Offline and peer-to-peershort gaps onlydesigned for it
Memory per documentclose to the text sizeids and tombstones, compressed runs
Main difficultytransform rules per operation pairinterleaving, tombstone cleanup
Typical fitalways-online editor with a serviceoffline-first, local-first, end-to-end encrypted
Both converge; they differ in where the complexity lives.

7Follow-up questions

Why does a CRDT make end-to-end encryption easier?

Because the server never needs to understand the operations. With OT, the server must read positions to transform them, so it sees the content. With a CRDT, clients can encrypt operations and the server only stores and relays them; clients merge after decrypting.

Can tombstones ever be removed?

Yes, once every replica that might refer to them has seen the delete. With a central server that knows all active clients, the server can compact the document at a point all clients have acknowledged; a client that was offline longer than that reloads a fresh snapshot instead of merging.

8Conclusion

In this answer, we saw that numeric positions break under concurrent edits and make replicas diverge. OT fixes the positions by transforming each incoming operation against concurrent ones, and with a central server that fixes one order it stays manageable; without one, the transform rules become very hard to get right. Sequence CRDTs replace positions with unique character identifiers and tombstones, so edits merge in any order, at the cost of metadata, tombstone cleanup and careful handling of interleaving. Server-ordered OT suits always-online editors, and CRDTs suit offline-first and peer-to-peer ones.

What to say in the interviewAbout 80 seconds aloud

Open with

The problem is that operations use positions, and a concurrent edit shifts them. If Ann inserts cat at 10 and Bob deletes 8 to 11, applying them naively in different orders gives two different documents.

Then, if they want more

OT fixes this by transforming an incoming operation against concurrent ones already applied: the insert inside the deleted range moves to its start, and on the other side the delete splits around the new text, so both get 01234567catCDEF. With a central server that assigns one order, each client only transforms against the server's sequence, which is manageable.

Without a server, the transform functions must satisfy stronger properties for every pair of operation types, which is notoriously hard with rich formatting. A sequence CRDT avoids positions altogether: each character gets a unique id like replica plus counter, inserts say after this id, deletes leave tombstones, and the merge rules give the same order in any delivery order.

The costs are per-character metadata, tombstones that can only be removed once all replicas have seen them, and interleaving at the same spot, which good algorithms handle and libraries reduce by compressing runs. I would use server-ordered OT for an always-online product, and CRDTs for offline-first, peer-to-peer or end-to-end encrypted editing.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How do operational transformation and sequence CRDTs each make both copies converge, and...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/d4258b139e/