Realtime

Table changes and broadcast over WebSocket, in the shape supabase-js expects.

/realtime/v1/websocket?apikey=<key>&vsn=1.0.0 speaks the protocol supabase-js uses. Two things travel over it: table changes and broadcast messages.

TypeScript
const channel = supabase
  .channel("notes")
  .on("postgres_changes", { event: "*", schema: "public", table: "notes", filter: "owner=eq.42" }, (p) => console.log(p))
  .subscribe();

Which tables send changes

None, until you say. Either list them in forkbase.toml:

TOML
[realtime]
tables = ["public.notes", "messages"]   # schema.table, or a table in the first REST schema

or add them while running, with the service key:

shell
curl -X POST $URL/realtime/v1/tables -H "authorization: Bearer $SERVICE" -d '{"table": "public.notes"}'
curl $URL/realtime/v1/tables -H "authorization: Bearer $SERVICE"
curl -X DELETE $URL/realtime/v1/tables/public.notes -H "authorization: Bearer $SERVICE"

Filters on a subscription: col=eq.value, with eq neq lt lte gt gte in.

Who sees what

  • The service key gets every change as written.
  • Everyone else gets an insert or update only if they may select that row, checked by primary key under their own role and policies at that moment, with only the columns they may select. A delete arrives as the row's primary key alone.
  • A table without a primary key sends changes to the service key only.
  • When a person's token expires, their channel stops getting changes. Send a fresh token (access_token) and join again. supabase-js does this on refresh.

Broadcast

Messages between the sockets joined to one topic, with self (receive your own) and ack (confirm delivery) as in supabase-js:

TypeScript
const room = supabase.channel("room-1", { config: { broadcast: { self: true } } });
room.on("broadcast", { event: "cursor" }, ({ payload }) => draw(payload)).subscribe();
room.send({ type: "broadcast", event: "cursor", payload: { x: 10, y: 20 } });

Limits

  • Changes travel by Postgres LISTEN/NOTIFY, so every Forkbase server on the same database sends them.
  • A row over about 8 KB arrives without its values (too_big); read it over REST.
  • Changes made while Forkbase reconnects to the database are not sent. Read the table again when a channel reconnects.
  • In chronos mode, rows an agent's merge wrote are not sent (the engine merges without running triggers).
  • Not yet: presence, private channels.

Something wrong or missing? Edit this page on GitHub or open an issue.

Realtime · Forkbase