<youtube.com/watch?v=fB_lklm7xgU> (hazel, unison, ...
# linking-together
d

youtube.com/watch?v=fB_lklm7xgU▾

(hazel, unison, crdts)
does anyone have experience with both CQRS / event sourcing and CRDTs? My suspicion is that for most of my use cases (collaborative software development and collaborative products) CRDTs add a lot of complexity despite the initial magic
d
@Dev Doshi i'm doing a lot of that right now. specifically, an event based system is a great way to make your groundtruth the CRDT and reactively do work downstream.
I'm not sure what you have in mind regarding the complexity. If you have to be eventually consistent, that's not accidental complexity. There are event sourcing shaped synced engines like https://livestore.dev but sync engines don't cover all usecases of a CRDT.
d
Yes, Johannes/livestore is the only one I'm aware of, but afaik it is coupled to sqlite (or at least it was last time I looked)
I would love to hear more about your system @dman-os
d
If you look at electric SQL and Zero Sync, behind the curtains, they're also using events streams in some form https://electric.ax/blog/2025/12/09/announcing-durable-streams
But these don't really let you do offline writes out of the box.
Multiple writers under a partitioned network...
Or generally...the local-first principle of using thick clients over dumb, interoperable, replaceable backbends is served better by CRDTs https://www.inkandswitch.com/essay/local-first/
Well, you can still use small, partitioned, contactable durable event streams for such usecssss...I'm building CRDTs over such a primitive and you can also look at willowprotocol.org
But modern CRDT libraries, you get a standalone artifact that works for a lot of use cases, independent of network properties.
d
Let's say you were building something like couchsurfing or airbnb, where would you use or not use crdts?
d
A local-first AirBnb you mean? CRDT is mainly a good fit for multiwriter scenarios. If you're really local-first and must accept network partitions...for example, you'd want to have some kind of CRDT based lease system here to disallow double bookings.
💯 1
If you have a single authoritative server and all writes require users to be online, CRDTs are less useful.
d
Most things I want to build have some local or offline capabilities and have business logic like bookings and non trivial authorization and need operational/admin dashboards. As far as I can tell, things like automerge aren't considered production ready for most of those types of requirements. Meanwhile command sourcing works great for offline/local first and event sourcing has a story for all those requirements. And if I were to compare the amount and complexity of the code side by side, my suspicion is the crdt would have extra stuff. That's what I'm trying to explore
d
Yes, CRDTs and systems built on top of them like inkandswitch.com/keyhive/notebook are very difficult but if you want to make it multi-writer under long partitions, and especially e2ee, it's unavoidable.
for other folks tackling auth and e2ee for local-first
Note that if you have a these requirements, local-first, multi-offline writers and long partitions...you'd have to make your event sourcing logic a CRDT too.
d
As I mentioned, command sourcing works fine for local first multi offline writers. Typically conflict resolution belongs in the domain / application logic anyway, at least in my experience
d
True but imagine if instead of having to design CRDTs per domain, you had a single generic JSON CRDT impl?
d
You can compose/reuse code/domain logic in code whether it's crdt or event sourcing right?
d
To a certain degree. Depends on the underlying model. There are usecases where doign a special CRDT is warranted.
For example, p2panda and keyhive implement a CRDT for access control specifically.
Right now, I'm in the middle of designing a CRDTish thing for distributed task scheduling and i'm building it over key collapsed events.
But when doing local-first, you realize that everything must tackle with the multi-writer thing and thus you end up preferring to have simple generic things that have simple rules.
d
I'm not seeing anything crdts can do that event sourcing can't but I do see the opposite, I guess. I'll take a closer look at the links you shared
I've built several group chat and collaborative tools that are multiplayer offline first with command sourcing
d
You could do a JSON over event sourcing. In a way Automerge is exactly that. It's an append only list of (actor, object, operations).
d
Yes. Operational transforms are also basically a hard coded cqrs/es for text editing
It's just doing extra work IMO, so I'm basically trying to approach it from the perspective of what am I missing about crdts that make them preferable to people
d
I think the main sell is that you get a working black box you can stuff a JSON in.
d
Ok I'll have to dig up my old structured editor implementation and compare
d
I"m curious what the examplary event sourcing/CQRS system you have in mind looks like btw.
d
Yeah most I've made are proprietary for clients but I'm planning to demo some of mine at the next demo, maybe I'll make a collaborative editor for the demo
w
For real local-first collaboration I feel like you need Conflict-ful Replicated Data Types. I mean that you need to keep a trace of the conflicts but they could, for example, still resolve such that the data structure representing unresolved merges is, for example, order independent or at least re-orderable. Ideally I imagine something like a type-level function that takes a algebraic datatype and related functions, and returns a new datatype that allows for conflicts and non-determinism. There are some well understood functional programming monads that kind of do this, so someone has probably worked it all out already.
d
I didn't show my collaborative markdown editor in my demo @wtaysom but as I mentioned briefly above, I believe conflict resolution belongs in the app/domain not in the transport. In mine, every conflict can result in 0-many suggestions for how to resolve conflicts and then it's up to the users or additional code to react to those and perhaps auto-apply some resolutions. Those conflict resolution suggestions are read models / projections based on the state of the conflicts and the latest state. I find my style of CQRS/ES to be monad/comonad friendly but I don't tend to use libraries that encode those things, just interfaces that are aligned with those.
💪 1
d
I think you'll find most modern CRDT libraries to align with what you describe there. Since they carry full history and conflicts are clearly marked, applications can choose to do corrective edits. This is analogous to CQRS any ways because if you're doing multi-writer, the conflict resolutions can't be out of band and must be more commands.
d
I agree it can be done with CRDTs
d
Btw, you should also look at dedicated text editing CRDTs like peritext and egwalker that try to solve certain text editing specific merge issues that the generic CRDT algos struggle with.
My point being, designing correct merge semantics can be tricky. Out of the box solutions that don't require you to be have pedigree on the topic are a big value.
d
When I next dive into it I'll make sure they are on the list. I did have my agent extract test cases from the literature and repos on CRDTs but I didn't review them in detail
👍 1
I'm also curious if there's discussion around which conflicts to intentionally not support because they aren't likely, or add too much complexity, or based on the authoring type (markdown, text, code, json, etc.)
d
The CRDT algorithms elect to never reject merges, merge always succeed unsupervised unlike git. It's just that sometimes, the end result is semantically invalid despite being valid for the transport. Not support just means that the semantic degradation is not guarded against.
👍 1
Peritext for example works well for guarding against bad merges for annotations of text like marking a span as bold or italic concurrently.
👍 1
Also, one thing that Automerge recently added is signing the changes/transactions. So the transport could maybe consult some other authority to reject syncing writes from unauthorized writers. This is beyond the CRDT algorithm itself tho.
*even tho it's enabled by the CRDT design
d
cool, yeah that makes sense. Elsewhere here I was asking related questions for ATProto and it seems like that is the general design; additional facts/writes from an authority
I'll keep an eye on developments for sure, wish I had time to contribute (and also knew what needed to be contributed haha)
d
ATProto is pretty cool, my pet project is at the intersection of p2p, crdts and atproto. But yeah, event sourcing is indeed what enables most of these technologies at the core.
🙌 1