drift Docs
Pages
drift Docs
Start
What is Drift?
The tour, if you are new here.
Use cases
Whether Drift does your thing.
Getting started
Nothing to deployed, in one command.
Architecture
How a slice is put together.
What it costs
The free grant, four unit prices, two rules.
Moving off Azure
Estimate, snapshot and transform a resource group.
Build
Canvas
Static sites, same origin as your API.
Tools
Operate
Auth
Route gates, API keys and your account.
Teams
More than one person on one account.
Security
Boundaries, sandboxing and hardening.
Troubleshooting
Error codes
What went wrong, and what to do about it.
Legal
Acceptable use
What a slice may not be used for.
Data processing
The DPA, and every sub-processor.

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.

The upgrade checks three things: the channel name's charset, the 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.
Node.js
// 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.

Driftfile
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:

Go
// 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

LimitBehaviour past it
Channel name: alphanumerics and : . _ ~ -, 1–256 bytesThe upgrade answers 400.
512 KiB per messageThe frame is dropped silently, and no error reaches the sender.
128 connections per channelThe socket is closed with code 1013, "channel full".
2,048 live channels per sliceClosed the same way.
Concurrent connections across the slice, set with realtime_connections in the Driftfile's slice limits blockThe upgrade answers 503. A slice with no positive value caps at 50.

Realtime is a shared channel between many clients.

To stream a response from a single function call instead, set stream = "sse" or stream = "ws" on the function; see Atomic streaming.