Realtime Concepts
Supabase Realtime lets you to build real-time applications with collaborative/multiplayer functionality. It includes 3 core features:
- Broadcast: sends rapid, ephemeral messages to other connected clients. You can use it to track mouse movements, for example.
- Presence: sends user state between connected clients. You can use it to show an "online" status, which disappears when a user is disconnected.
- Postgres Changes: receives database changes in real-time.
Channels#
When you initialize your Supabase Realtime client, you define a topic
that uniquely references a channel. Everyone connected to the same Channel topic
receives the same messages.
_10import { createClient } from '@supabase/supabase-js'_10_10const client = createClient('https://<project>.supabase.co', '<your-anon-key>')_10_10const channel = client.channel('my-topic') // set your topic here
Clients can bi-directionally send and receive messages over a Channel. The Realtime backend can also push messages to all clients connected to the same Channel.
A single client can receive change records from Postgres, Broadcast messages from other clients, and Presence updates all over the same Channel.
Choosing between Broadcast and Presence#
We recommend using Broadcast by default, and then Presence when required. Presence merges all changes into a shared state for every client connected to the same channel. If you use Presence, it's best to throttle your changes so that you are sending updates less frequently.