NEXIS
Guides

State Synchronization

How snapshots, patches, and acknowledgements work.

State Synchronization

Nexis syncs room state through two message types:

  • state.snapshot: full room state
  • state.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.resync if sequence gap or checksum mismatch

Sync flow

  1. Receive state.snapshot on join.
  2. Store (state, seq, checksum?).
  3. On each state.patch, verify seq ordering.
  4. Apply patch ops.
  5. Ack latest sequence.
  6. 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.

On this page