Guides
State Synchronization
How snapshots, patches, and acknowledgements work.
State Synchronization
Nexis syncs room state through two message types:
state.snapshot: full room statestate.patch: incremental update ops
Patch Shape
{
"seq": 43,
"ops": [
{ "op": "set", "path": "/counter", "value": 4 },
{ "op": "del", "path": "/foo" }
],
"checksum": "optional"
}Client responsibilities
- apply patches in order (
seq) - keep local state consistent
- ack processed updates with
state.ack - request
state.resyncif sequence gap or checksum mismatch
Sync flow
Recommended client loop
- Receive
state.snapshoton join. - Store
(state, seq, checksum?). - On each
state.patch, verifyseqordering. - Apply patch ops.
- Ack latest sequence.
- If mismatch is detected, request
state.resync.
let = 42;
function (: ) {
if (. !== + 1) {
();
return;
}
(.);
= .;
(.);
}
declare function (): void;
declare function (: []): void;
declare function (: number): void;Initial state
On successful room join, client receives state.snapshot so UI can render immediately.