Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

CRDTs are pretty rad, I’m really excited to see what the future might hold for them particularly around development


They’ve been rad for years, and a lot of work has been done around them.

Usually people find that there are simpler/better ways to get the job done.

I think they’re better left as an implementation detail at this point.


> Usually people find that there are simpler/better ways to get the job done.

CRDTs can do one magic trick no other technology solutions can do: They can let users collaboratively edit without needing a centralized server. And this works between users, between devices or between processes.

Its just, most of the time that doesn't matter. Servers are cheap, and big companies frankly seem to love it when we're dependent on their infrastructure.

I want CRDTs for more "personal computing". I want my data to be shared between my devices seamlessly. And I want that to keep working even when I can't contact google's computers. I also really like something about Git - which is the fact that my computers are first class citizens in a repository. Unlike Google Docs, if github ever goes down, I don't lose any data and I can still get my work done, and collaborate with my teammates.

All software should work like that. I'm fighting to make CRDTs work well so we can bring that future within reach.


To OP's point, which I secretly wished I had the courage to post when CRDTs came up a couple times last week: I've been seeing these posts, and your comment, for what feels like my entire 13 years on HN. (That can't be true. But I distinctly recall someone saying "if they can do text this fast hey'll be able to do arbitrary JSON soon!" at least 5 years ago)

At the beginning of that period I made and sold a startup on having a dead simple sync strategy, by myself, while I watched 3 funded competitors try to build sync, fail and go under. I had no funding and no CS education, I was a waiter.


Arbitrary JSON has been done plenty of times, and it works great. Automerge, Yjs and ShareDB all manage it.


I don't quite understand what's going on then because I swear I just read in one of those threads last week that even the best text automerger still needs manual intervention to avoid creating nonsense...which, to be honest, sounded off because I thought this whole thing was popularized by Google Docs? Wave? and it didn't have that issue


Can you link the other comment? Its hard to know what you're talking about without that context.

In any case, you can't use a text "automerger" to collaboratively edit JSON text. (Whats an "automerger"?)

To understand why, suppose we had an empty (JSON) list: []. Two users concurrently inserted two items, "a" and "b". If those inserts get translated into string inserts, you end up with a JSON string containing ["a""b"] - which is a syntax error!

The trick to making this work correctly is that the CRDT / OT system needs to understand that you're editing a list. Don't collaboratively edit the JSON string. Collaboratively edit a list then JSON.stringify the result.


There's a possibility he's talking about what I wrote about CRDTs for syntax trees - https://writer.zohopublic.com/writer/published/grcwy5c699d67...

Related HN thread: https://news.ycombinator.com/item?id=29433896


> the best text automerger still needs manual intervention to avoid creating nonsense

AFAIK the best production-ready CRDT solution for text is Yjs [0], and in some specific cases, the result of the merge might be something unexpected (one example [1]). However, there is research-quality CRDT called Peritext [2] which is specifically designed to handle styled text in an intuitive way, so the merge is more predictable.

[0]: https://github.com/yjs/yjs

[1]: https://github.com/yjs/yjs/issues/382

[2]: https://www.inkandswitch.com/peritext/


I don't think this comment makes much sense, arbitrary unicode text is very different than JSON. What application domain are you talking about?


> Servers are cheap, and big companies frankly seem to love it when we're dependent on their infrastructure.

I've worked on a few different sync engines for mobile apps over the years, it's also a matter of user expectations in consumer apps. Users expect to seamlessly pick up where they left off on another device and the absence of an intermediary server makes that difficult.


You can always have an intermediary server with CRDTs is you want. They're just another peer on the network.


Yeah I'm aware - I got the impression from your comment you were advocating for a more pure P2P approach (not necessarily CRDT related).


I am. I guess thats something I really like about git + github - you get the best of both worlds. Github is fantastic, and you can use github all day long. But you don't depend on it. If github had an outage like atlassian is having at the moment, there's no downtime. There's no risk of data loss. You can keep working and if you need to you can always move to gitlab or self host.

The downside is you sort of have the worst of both worlds in terms of complexity. You need a working, performant CRDT and a working centralized server. But I think its a great model that we (as an industry) should explore more.


Yeah I agree it's great from that perspective but the business goals very rarely make it a priority given the added complexity. Even supporting offline-first style workflows is step up as you can tolerate more downtime on the backend as your app doesn't become completely useless.


Usually people find that there are simpler/better ways to get the job done.

Here's all the ways I know for dealing with write conflicts in a distributed systems:

- Last write wins, AKA I'm going to pretend I've solved the problem and just randomly lose data

- Record all versions of the data, pick an arbitrary winner, store a revision, and surface it to the user if there's a conflict (the CouchDB strategy, I don't know anything else using this)

- Model your data so it's append only (events, maybe) then merge just becomes a set union of all the different nodes[0]

So including CRDTs, that's my general taxonomy of solutions to this problem. Are there more?

[0] Working on a prototype for this right now, if anyone has done similar work I'd love to pick your brain, email in profile.


CRDTs don’t quite fit in this list, as these are all valid merge strategies that a CRDT can use. The fundamental idea of a CRDT is that all of these schemes have something in common: They’re based on iteratively merging a bunch of versions together with a merge operator that fulfills a few basic properties (where + means merge:

- Associativity: (A + B) + C == A + (B + C)

- Commutativity: A + B == B + A

- Idempotency: A + A = A

- Closure: Every merge result is a valid merge argument

- (perhaps a few others; it’s been a while since I read the original papers)

As long as your merge operator has all of these properties, you get the strong eventual consistency result that makes CRDTs a useful abstraction: Any two users that have received versions including the same updates will reconstruct the document in the same way, even if the actual set of versions seen differs.


That part is clear to me. What's not immediately obvious is that the DT in a CRDT can be entire database. Certainly the focus seems to be on individual data structures within a data store.

Might have to re-read the papers with this thought in mind. It did seem like there was a duality there but I kind of dismissed it.


A CRDT is still just a data structure. Most of my work lately has been on building an operation based CRDT for lists. Storage wise, you basically just store the set of all the operations you know about. (Though you can trim that set down if you want, like a shallow git clone).

You can store that set of operations just as easily in a file or in a database table. (Though the table will take a bit more space on disk because you can't be quite as clever).

To generate the data value itself, you can either replay all the operations from scratch (which is not as bad as it sounds), or store a cached copy of the data at some version and use that. You can think about it as, the operations give you history, tell you how to merge in remote changes and contain the data remote peers need to sync. The data itself is the value you read out & display.

There's nothing special about the data itself. You can store all that data in a flat file, or a database table, or in a few arrays in memory. The fancy part is (usually) how you merge changes together.


The conditions referenced in GP seem to imply that the most general state-based CRDT is simply a set of all reported outcomes. Something commutative, associative and idempotent is basically describing set union. So whether it's easy to go from one to the other would seem to depend on what constraints you're enforcing on your database.

Operation-based CRDT's are a bit different, these require commutativity and associativity. So you would be dealing with a multiset of reported operations.


Slightly pedantic, but I think you'll actually find that all of these are CRDTs. If you read "Conflict-free Replicated Data Types: An Overview" (https://arxiv.org/pdf/1806.10254.pdf), it refers to both last write wins and "record all versions of the data" as CRDTs in 2.1.1.

My understanding is that "CRDT" really just means that you've defined how you're going to resolve conflicts consistently (see criteria in s2.2 of the paper above).


Yeah it had occurred to me that what I'm doing was just a GSet writ large. In my mind a CRDT was always a single record, not a collection of them - still not convinced that doesn't change it.

But if CRDTs really are a kind of a meta-language for resolving conflicts in a sane way - whether the CRDT is a single record or a whole data store - that's a nice thought. The CouchDB CRDT could be defined.


The pessimist in my brain keeps waiting for someone to prove mathematically that they’re impossible. NP complete might be fine for many uses, since the branching factor for code for example is pretty low. But for some people NP complete is a magical force field that shuts off all rational thought.


Yes. There is a paper that shows that if a data type has non-commutative operations, then avoiding expensive synchronization is impossible

https://hagit.net.technion.ac.il/files/2015/09/popl168gf-att...


That agrees with my intuition for the most part, although it might carve out some space for hope, in the sense that a paper about proof of A that doesn't mention !A means someone spent time in there and didn't find a bigger problem. The more times someone carves out a small amount of negative space in a problem domain, the higher the odds are that there's an asymptote that is nonzero.

What I'm more worried about is that we will prove that 'interesting text merges' are not all commutative. Though one trick we keep doing in spaces where things are proven impossible is that we cheat by creating tools that disallow or discourage the intractable scenarios. That could, for instance, lead to a generation of programming languages with a strange file structure that makes most workflows commutative.

That may sound strange or terrible to some people, but it's been my opinion for a number of years now that most of our coding conventions boil down to issues of avoiding merge conflicts, so a language that enforced a stronger form of conflict avoidance would be an 'opinionated' language but within the realm of the sorts of things we already put up with. Maybe no stranger than pure functional or Actor based languages, for instance.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: