sbarbase
Contents

Realtime

Realtime lets clients listen to database changes, and send broadcast and presence messages to each other, with supabase.channel(), as on Supabase. Each environment turns it on for itself.

Turn it on

  1. Open the environment in the console, then Services.
  2. Under Realtime, press Turn on Realtime. It shows Applying…, then On, usually within a minute.

Only owners and admins of the client see this section. If the server does not have the memory or the database connections for another Realtime, the section says so and nothing changes; see choosing a server.

Use it

Nothing changes in your application: point supabase-js at the environment's address with its publishable key, as for everything else.

const channel = supabase.channel('room-one')
  .on('broadcast', { event: 'hello' }, (message) => console.log(message.payload))
  .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'messages' }, (change) => console.log(change.new))
  .on('presence', { event: 'sync' }, () => console.log(channel.presenceState()))
  .subscribe()

How it runs

Each environment that turns Realtime on gets its own small Realtime service (the original upstream image, pinned). It uses up to 320 MiB of memory and stops when you turn Realtime off. It signs in to that environment's database only, with its own login.

When Realtime first starts, and after an upgrade to a newer Realtime, its login is given administrator rights for the few seconds Realtime needs to create its own schema, as upstream Realtime expects. The rights are taken away, and every session that had them is closed, before the start finishes.

The socket and the broadcast API go through the same gateway as REST: a wrong or revoked key is refused before anything reaches Realtime. Realtime's own management API is never reachable from outside.

CI turns Realtime on for an environment on a clean machine with every change, has two supabase-js clients exchange a broadcast, share presence and receive a row inserted through REST, checks that a wrong key is refused, and turns it off again (evidence).

Limits

Edit on GitHub