Kevin Jahns
Modern State Synchronization Solutions for Collaborative Apps

Single User Applications
- VSCode
- LibreOffice
- Inkscape

Web Applications
- Wordpress
- Drupal
- ..









Conflict Resolution: Last Writer Wins
Conflict Resolution: Duplication




Manual Conflict Resolution

Realtime & Automatic Conflict Resolution

Replicated Data Types (RDT)
- Abstraction for storing application state
- Optimistic Replication
- Observable
Replicated Data Types (RDT)
- Abstraction for storing application state
- Optimistic Replication
- Observable





RDT Example: Yjs
import * as Y from 'yjs'
const ydoc = new Y.Doc()
const webrtcProvider = new WebrtcProvider('room-name', ydoc, { password: 'optional-room-password' })
// const websocketProvider = new WebsocketProvider(url, 'room-name', ydoc)
// const matrixProvider = new MatrixProvider(ydoc, matrixClient, {type: "alias",alias: "matrix-room-alias"});
const ymap = ydoc.getMap('map')
const yarray = ydoc.getArray('array')
const ytext = ydoc.getText('text')
const yxml = ydoc.getXmlElement('el')
ymap.observe(event => {
console.log(event.changes.keys) // { "my key": { action: 'add', oldValue: undefined } }
})
ymap.set('my key', 'new value')

Lexical Editor


Lexical Editor



SyncedStore


SyncedStore
import React from "react";
import { useSyncedStore } from "@syncedstore/react";
import { store } from "./store";
export default function App() {
const state = useSyncedStore(store);
return (
<div>
<p>Todo items:</p>
<ul>
{state.todos.map((todo, i) => (
<li key={i} style={{ textDecoration: todo.completed ? "line-through" : "" }}>
<label>
<input type="checkbox" checked={todo.completed} onClick={() => (todo.completed = !todo.completed)} />
{todo.title}
</label>
</li>
))}
</ul>
<input
onKeyPress={(event) => {
if (event.key === "Enter") {
state.todos.push({ completed: false, title: event.target.value });
target.value = "";
}
}}
/>
</div>
);
}
SyncedStore


Relm.us


RDT: Business appeal
- Quick prototyping
- Realtime & collaborative
- Little setup
- No backend logic
- (Pay as you go)
- (snapshots)
- (offline support)
Control
Control
Image is CC: https://www.flickr.com/photos/nossreh/10987353554
Data
Conflict Resolution

Centrality
source: https://www.printablee.com/post_50-states-printable-out-maps_185196/

Centrality


Why can't my favorite file syncing service sync directly to my phone. Instead I first upload to the US, and then sync back
Centrality / Central Place of Control
+ Easier to coordinate
- No direct sync
- No sync if service is not reachable
- Harder to scale
Conflict-free RDTs: CRDTs
Alternatively: Coordination-free RDT
I.e. RDTs that don't require centrality

Y CRDT
• Implementation of different CRDTs (YMap, YText, YArray, ...)
• Ported to different programming languages:







Shared Control
Data
Conflict Resolution
Sync Peer-to-Peer



Sync on the Edge





Make it Available Offline








twitter.com/kevin_jahns

State Synchronization
By Kevin Jahns
State Synchronization
- 183