Docs/Start here

Durable state, one shared definition

Understand the client–hub model and choose the shortest path to your first synchronized feature.

Live protocol tracecounter://
Client A00
dispatch
Hub00
broadcast
Client B00

Starting the shared counter…

SEQORIGINENVELOPE
—Waiting for a dispatch—
On this page 5

Durable Channel keeps realtime state at a URI and gives that state a small, explicit protocol. You define the state shape and every allowed change once. The hub owns the authoritative instance; clients mirror it by running the same pure reducers.

The model in one minute

A channel definition combines a Valibot state schema, an initial value, named actions, commands, and notifications. Mount definitions on URI templates to make a route map, then give that map to both the hub and the client.

The hub orders accepted and rejected actions under one global serverSeq. A connected client applies its own action optimistically, then reconciles when the authoritative envelope returns. Other clients apply that same envelope to the same reducer.

client dispatch → optimistic state → hub validates → reducer → persist
                                                       ↓
other clients ← same reducer ← committed envelope ← broadcast

Pick a path

What Durable Channel owns

Durable Channel owns state validation, ordered commits, subscriptions, optimistic reconciliation, replay, snapshots, and enforcement of declared channel permissions. It carries a host-authenticated, typed principal through connections and handlers, but your application still defines the authorization policy and owns credential verification, revocation, reconnect timing, backoff, deployment, and the transport host.

That boundary is deliberate. The core uses web-standard APIs, while the JSON-RPC and WebSocket layer lives separately in rpc.ts and transport.ts.

A useful vocabulary

Term Meaning
Channel A definition plus one stateful or stateless protocol
Route A URI template mounted to a channel definition
Instance The state stored at one concrete URI
Action A named, validated state transition
Command Typed server work with a result
Effect Server work triggered after an action commits
Notification A live, ephemeral message that is never replayed
Envelope The ordered record broadcast for an action
Principal Optional host-authenticated identity attached to a connection
Client policy Server-side permission check for subscriptions, actions, and commands

Before you build

durable-channel is published to npm. Install it with npm install durable-channel or deno add npm:durable-channel; the examples in these guides import that package with Valibot.

Follow the signal from definition to wire.

Ten guides, ordered by the decisions you make while building.