Introduce yjs to share state
- Deciders: Julian Bäume
- Date: 2025-06-05
Status
Proposed
Context
We want to share state between multiple users in real-time, for example to allow them to collaboratively interact on a mail thread. Especially with unstable network connections, this can be challenging, as we want to ensure that the state is consistent across all users and that changes are propagated correctly. We also want to ensure that the state can be persisted and restored, so that users can continue working after a disconnection or a restart of the application.
This scenario is also very close to offline usage, where a shared state between client and server can be used to synchronize changes after a disconnection or a restart of the application.
Such use cases are covered by a pattern called CRDT (Conflict-free Replicated Data Type). CRDTs are data structures that allow for concurrent updates and can be merged without conflicts. Yjs is a JavaScript library that implements CRDTs and provides a way to share state between multiple users in real-time.
Some resources:
Decision
We are going to explore Yjs and its capabilities by implementing a proof of concept.
Consequences
While Yjs has a solid documentation and a large community, it's still a complex technique that requires a different way of thinking about state management as we currently are used to. This can be challenging especially for new developers. Deep understanding of the concepts require reading papers and source code. Fortunately, as Yjs is a mature library, there are many resources available to learn from and a lot of problems have already been solved by the community.

