News for hackers. Stuff that matters.
Re:Are CRDTs suitable for shared editing? by lewisjoe on Monday August 17, 2020 @09:13AM (#24186883)
I’m part of the team that makes Zoho Writer (Google Docs alternative) - https://writer.zoho.com

Back in 2009, we wrote our real time collaboration component using Operational Transformations (OT). But when CRDTs started to gain the spotlight, these are the reasons why it didn’t warrant a rewrite to our stack:

#1 Memory issues with tombstones. Marking as deletion has a cost of maintaining them throughout the session.

#2 CRDTs were perfect for plain strings and arbitrary key/value pairs. But when it comes to schematic JSON that has semantic value CRDT was an added overhead. For example, try making a collaborative HTML editor with support for table operations. It is very likely you will end up with a table structure that is invalid to render. In OT analysing, modifying or cancelling ops were much easier.

#3 Since the software is primarily a cloud document editor, a central server is necessary even otherwise. So why not use the server for efficient version management and operation sequencing as well? Why prefer CRDTs whose bulk of complexity comes from eliminating the need of a central system?

Such practical reasons have kept us from venturing into CRDTs. As of now, common editing platforms like Google Docs, Zoho Writer, CKeditor, ProseMirror, Quill, CodeMirror - all of these work with OTs instead of CRDT for collaborative editing.

Re:Are CRDTs suitable for shared editing? by cryptonector on Monday August 17, 2020 @11:59AM (#24188447)
Also, if the monoids used in a CRDT implementation do not align with the mental model users have for what they're doing (hint: they do not), then the result will be artifacts the users don't like. Single user text editing is amenable to using ropes and monoids internally because none of that leaks into the UI/UX, but multi-user text editing is not amenable to representation as monoidal interactions because in the multi-user case the monoidal interactions will become evident and confusing.

Or at least that's the lesson I took from all the xi blogs I've read.

Re:Are CRDTs suitable for shared editing? by hinkley on Monday August 17, 2020 @12:41PM (#24188900)
This is a problem we need to solve with code editors and version control as well.

Patches are always a little bit garbage, and can cause extra problems with 3 way merges because of it.

Re:Are CRDTs suitable for shared editing? by Chris2048 on Wednesday August 19, 2020 @10:37AM (#24210801)
In feel this is probably a language-level problem, and solving it only at editor/VC level will be complicated.

At the same time, changes to the lang level would require changes at editor/VC level too.

As en example: a MIX type syntax can separate classes and class-methods into different files, and combine them back again. This way moving a class method around in a class won't be seen as removing a method and creating a new one: the file give the specific method an identity, and a method of differentiating between code movement and code alteration.

Re:Are CRDTs suitable for shared editing? by dnautics on Monday August 17, 2020 @03:07PM (#24190644)
I think it's important to note that "they do not yet". CRDTs are an active area of research, relatively young, and it is not unreasonable to expect that new datastructures which DO align to users' mental models will appear in the not-too-distant future.
Re:Are CRDTs suitable for shared editing? by cryptonector on Monday August 17, 2020 @03:40PM (#24191050)
CRDT is very well understood. The basics of the theory is utterly trivial. The only question is whether we can design new monoids that line up better with human understandings of their own intent -- of this I am skeptical because our mental models of what we're doing are not at all monoidal, though because CRDTs are so elegant and so simple, I would be ecstatic if indeed we find/design such monoids.
Re:Are CRDTs suitable for shared editing? by dnautics on Monday August 17, 2020 @04:41PM (#24191789)
what do you think of Martin Klepmann's research, e.g: https://martin.kleppmann.com/2020/07/06/crdt-hard-parts-hydr...
Re:Are CRDTs suitable for shared editing? by cryptonector on Monday August 17, 2020 @05:45PM (#24192556)
I'll watch it and let you know. Sounds very interesting!
Re:Are CRDTs suitable for shared editing? by cryptonector on Tuesday August 18, 2020 @12:17PM (#24200562)
I'm part of the way through. Here are some thoughts.

- Is there a way to materialize all of the past up to some point, throwing out history in the process, so as to reduce the overhead of CRDT?

- Some CRDT algorithms (really, representations of operations) are better at modeling a user's intent -- rather than "insert 'H' at 101, insert 'e' at 102, ..." and so on, it's "insert 'Hello' between ...". As I'm not familiar with OT, I wonder whether this begins to approach OT... In any case, some of the better CRDT algorithms for text editing tend to require more overhead, which is why the preceding thought.

- I'm much more interested in CRDTs for distributed relational databases, where it's much easier to reason about intent. "Relational" really means "has a well defined, enforced schema", while "text" means "anything goes" -- it's necessarily easier to reason about the former than the latter! Even so, a set of related updates to a relational database may be the complex result of a simpler abstraction -a simpler operation that the user intended- and eventual consistency semantics may ruin that result. One way to deal with that is to centralize certain kinds of operations, but those had better be less essential to business continuity.

Re:Are CRDTs suitable for shared editing? by dnautics on Tuesday August 18, 2020 @03:55PM (#24203559)
thanks for those thoughts!

- I'm with you on point #1. Obviously could be a source of good research, but also, it probably depends on policy. How many undos do you want to preserve? Even a one-headed VSCode instance only saves so many undos. You could probably hybrid CRDT with a consensus algorithm like raft to perform compactions.

Re:Are CRDTs suitable for shared editing? by cryptonector on Tuesday August 18, 2020 @05:50PM (#24204773)
Right, if it's about undo history, screw that, at some point you don't care anymore -- you might build a sort of VCS into the text editor so you can keep track of changes in a less granular way. If it's about knowing when you have all the history before some point in time, then that's doable.

And thanks for the link!

Re:Are CRDTs suitable for shared editing? by fastball on Monday August 17, 2020 @10:04AM (#24187305)
I think the main impetus for this post is to assert that #1 and #2 aren't much of a problem for Yjs, as they are for the arguably more well-known CRDT lib for JS, Automerge.

With respect to #3, one reason to prefer CRDTs over OT (even if a central server is required for other stuff) is that making the collaboration infra P2P can save a lot of resources if most of your collab is happening between a few individuals at a time. Not very necessary at a small scale, but if you have 10,000 small teams collab'ing, the cost savings you get from off-loading RTC to the end users can definitely add up.

Re:Are CRDTs suitable for shared editing? by lukevp on Monday August 17, 2020 @12:55PM (#24189057)
OT doesn’t require a central server, just a tie breaker. You could just do leader election over webRTC using raft and offload OT to the client side as well and have that node push updates to the server for durable saving every x seconds and shift RTC off your infra.
Re:Are CRDTs suitable for shared editing? by raphlinus on Monday August 17, 2020 @01:12PM (#24189258)
Right, the idea that OT requires a "central server" is a bit of an oversimplification. It requires an authority that can serialize concurrent revisions into a globally consistent sequence. By far the easiest way to achieve that is an actual central server, but distributed algorithms have also been published for a long time, for example SOCT2 which uses a state vector.

The downside is the complexity. Now there are more things that can go wrong: the OT algorithm can fail (either due to bugs or because of corrupted data), and now also the distributed consensus algorithm can fail as well. When you have this level of complexity, going to CRDT is pretty appealing as an alternative.

Re:Are CRDTs suitable for shared editing? by ianopolous on Monday August 17, 2020 @11:25AM (#24188147)
What do you think of Chronofold [1]?

[1] https://arxiv.org/abs/2002.09511

Re:Are CRDTs suitable for shared editing? by zzz61831 on Monday August 17, 2020 @10:23AM (#24187522)
> Memory issues with tombstones. Marking as deletion has a cost of maintaining them throughout the session.

That's not true, you don't need to keep them throughout the session. You can drop them as soon as you either synchronize with other clients or with the server, which can then synchronize with the clients, that's what conflict-free nature of CRDTs allows you to do. The only fundamental requirement is to keep track of changes when you are offline or out of sync until they are sent to others and even then you are supposed to merge those changes into fewer changes keeping disk and memory use down to a minimum.

> CRDTs were perfect for plain strings and arbitrary key/value pairs. But when it comes to schematic JSON that has semantic value CRDT was an added overhead.

Also not true. They were never perfect for plain strings, even incompatible semantically, but perfect for sets, counters, numbers, where basic commutative math is enough, a few other things and anything that combines those primitives into more complex ones, especially true for schematic structures, tables.

You should really try implementing CRDTs, especially OP-based, they change the way you think about keeping shared state in distributed systems.

> Since the software is primarily a cloud document editor, a central server is necessary even otherwise. So why not use the server for efficient version management and operation sequencing as well? Why chose CRDTs whose bulk of complexity comes from eliminating the need of a central system?

There is zero complexity in CRDTs that comes from eliminating the need of a central system, it's a completely different problem orthogonal to CRDTs. Central systems is where CRDTs are used the most actually.

Re:Are CRDTs suitable for shared editing? by lewisjoe on Monday August 17, 2020 @10:41AM (#24187738)
> You can drop them as soon as you either synchronize with other clients or with the server

Say 100 nodes edit a doc. To drop a tombstone, without a central server we need 99 acks. Even with a server, the server keeps an ever-growing list of ops unless it uses some garbage collection techniques. And as stated by OP those techniques have their own problems. Remember, OP relies on V8's hidden classes for deriving an optimal representation without eliminating tombstones. Servers though need not necessarily hold CRDTs in JS. It might be a different VM altogether.

> anything that combines those primitives into more complex ones, especially true for schematic structures, tables.

I'm not implying CRDTs are only for simple structures. Automerge has support for tables too. I'm talking about structures with semantic meaning. In database tables the ops are always inserting/delete columns/rows and updating cells. In HTML tables, it extends into cell-merging, cell-splitting, inner tables and all sorts of valid operations. Merging these operations without inspecting the op and writing a custom modifier - will certainly end up in an invalid table structure.

> Central systems is where CRDTs are used the most actually.

I'm assuming the central system referred here is the database resilience systems using CRDTs to merge. Database syncing without master/slave is exactly the kind of problem best solved with CRDTs. The very point is to eliminate the need for a central point of failure.

Re:Are CRDTs suitable for shared editing? by kevinjahns on Monday August 17, 2020 @11:29AM (#24188168)
OT comes with very different problems when it comes to representing tables. Structured content (tables, tables containing tables, tables containing quotes containing tables, ..) is much better represented using CRDTs.

And another note, Yjs completely supports the OT rich-text type (i.e. delta format [1]). This is how the Quill editor was made collaborative.

So Yjs is at least as powerful as OT. If you want, you can still base your application around OT deltas, but Yjs is IMO much easier to use.

[1]: https://quilljs.com/docs/delta/

Re:Are CRDTs suitable for shared editing? by lewisjoe on Monday August 17, 2020 @11:36AM (#24188235)
> So Yjs is at least as powerful as OT.

Sounds interesting. Will give Yjs a try!

Re:Are CRDTs suitable for shared editing? by kevinjahns on Monday August 17, 2020 @11:57AM (#24188421)
Great! :)
Re:Are CRDTs suitable for shared editing? by zzz61831 on Monday August 17, 2020 @12:12PM (#24188602)
> Say 100 nodes edit a doc. To drop a tombstone, without a central server we need 99 acks. Even with a server, the server keeps an ever-growing list of ops unless it uses some garbage collection techniques. And as stated by OP those techniques have their own problems.

Here's how it could be done (very roughly):

When a client makes a modification, it creates an op representing that modification and includes a list of server identifiers to send the op to. Then queues the op. Once op is sent and ACKed by at least one of the servers the op is dropped from the queue.

Servers receiving the op synchronize the op with each other, ACKing each other and removing ACKed servers from the list. They also synchronize with the clients, sending the op to each client and asking clients to ACK to all servers. Obviously there are multiple ways to do it and it can be almost as efficient as theoretically possibly, but of course you can't avoid some metadata for each client associated with a particular document even though it doesn't have to be kept in server memory, it could be stored on disk.

> I'm talking about structures with semantic meaning.

Semantic meaning generally doesn't map to any data structure directly, CRDTs are not an exception here either.

Re:Are CRDTs suitable for shared editing? by toomim on Tuesday August 18, 2020 @02:45AM (#24195891)
> Then queues the op. Once op is sent and ACKed by at least one of the servers the op is dropped from the queue.

Unfortunately, it's a lot more complicated than this.

First, you can't wait until just one peer has ACKed -- you need to wait until all of them have. Any peer that hasn't ACKed could still send an op based on the one you want to delete, and then you wouldn't have enough information to merge the new op.

Second, you can't just wait until all peers have ACKed an op, you need to wait until no new ops depend on that op. An op could depend on an op even though it has been ACKed by everyone.

Third, a peer could go offline for a while, and then come back online. But if you are waiting for all peers to ACK an op, you might never get a situation where all peers are online at the same time.