Backbone Realtime
In-slice pub/sub over WebSocket. Browser clients open a socket to a named channel; anything one client sends is fanned out to every other client on that channel, live. There's no broker to run and no second service. The channel lives in the slice, same-origin with your Canvas site, so there's no cross-origin handshake.
A channel has no authentication.
DRIFT_ALLOWED_ORIGINS allowlist (an empty allowlist
permits every origin), and the slice's connection cap. Anyone who can reach your slice's URL and
knows or guesses a channel name can subscribe to it. What a visitor may send is yours to
decide: a frame a client sends is relayed only on a channel your Driftfile opens to clients, and is
dropped on every other one. Put nothing on a channel you would not hand to an anonymous caller, and
keep the privileged half behind a function.
// in your Canvas site's JavaScript: join a channel and react to others
const ws = new WebSocket(`wss://${location.host}/realtime/board:42`);
ws.onmessage = (e) => applyDelta(JSON.parse(e.data));
// broadcast your own change to everyone else on the channel
ws.send(JSON.stringify({ type: "move", x: 10, y: 20 }));Which channels a visitor may publish to
No channel accepts client frames until you open it. A visitor's browser can always
subscribe and receive, but a frame it sends is relayed to the room only when its channel is named in
the Driftfile's realtime block. Any other frame is dropped, counted, and the sender is
told once why; the room hears nothing.
backbone {
realtime {
client_channels = ["board:*", "chat"]
}
}
An entry is a channel name (chat), a prefix ending in *
(board:* opens every channel that starts with board:), or a bare
* for every channel. The list is the whole truth, up to 64 entries: []
closes every channel, and a file with no realtime block closes whatever an earlier
apply opened. The Driftfile reference has the block.
The list governs clients only. A function always may publish, because it runs on the slice and
never speaks as a stranger. A function cannot open a channel for visitors: the list is set by
drift apply, which holds the slice's credential, and a function does not.
A function can also publish to a channel server-side, fanning an event out to every subscriber, or check how many are connected:
// fan a message out to everyone on the channel; returns the recipient count
n, _ := drift.Backbone.Realtime.Channel("board:42").Publish(map[string]any{"type": "reset"})
live, _ := drift.Backbone.Realtime.Channel("board:42").Presence()This is what drives live cursors and collaborative editing in the Myral whiteboard demo: clients exchange cursor and backend deltas over the channel, and a normal function persists the result for durability and late-joiner catch-up.
Realtime limits
| Limit | Behaviour past it |
|---|---|
Channel name: alphanumerics and : . _ ~ -, 1–256 bytes | The upgrade answers 400. |
| 512 KiB per message | The frame is dropped silently, and no error reaches the sender. |
| 128 connections per channel | The socket is closed with code 1013, "channel full". |
| 2,048 live channels per slice | Closed the same way. |
Concurrent connections across the slice, set with realtime_connections in the Driftfile's slice limits block | The upgrade answers 503. A slice with no positive value caps at 50. |
Realtime is a shared channel between many clients.
stream = "sse" or stream = "ws" on the
function; see Atomic streaming.