Realtime
Realtime pushes Events, Messages and record changes to connected Apps and agents as they happen, resumable from a cursor.
Realtime pushes Events, Messages and record changes to connected Apps and agents as they happen. A client that drops resumes from its cursor and misses nothing.
Contract
- A stream is a live read by Event selector, such as
Order.*, under the caller's Permissions. - Every item carries a sequence number. A client reconnects with the last one it saw and receives every later item, in order.
- Streams run over web sockets or server-sent events at
wss:, with//api.sb/ <domain>/ events/ stream selectandcursorparameters. - Presence and typing reach a Channel's members live and are never stored.
- A stream is a read: it creates no Action per item. Open connections count against a Limit per Tenant.
- One Channel carries up to 1,000 Messages a second, then shards by Thread.
- An Agent in a Channel receives its Messages as they arrive. Dashboards refresh live for people.
Verbs
None.
Interfaces
Example
// crumbrun.com delivers from neighborhood bakeries. Each bakery's kitchen screen
// shows new orders the moment they are placed, and survives a dropped connection.
import { $ } from 'startup-builder'
const tickets = document.querySelector('#tickets')!
const cursor = localStorage.getItem('cursor') ?? undefined
for await (const event of $.stream('Order.placed', { cursor })) {
tickets.append(`${event.data.order.$id}\n`)
localStorage.setItem('cursor', String(event.seq))
}