Realtime

Realtime for every project

Subscribe to database changes, broadcast low-latency messages between clients, and track who is online — over websockets, with Row Level Security deciding what each user receives.

stitchdb
  .channel('todos')
  .on('postgres_changes', { event: '*', schema: 'public', table: 'todos' }, (payload) => {
    console.log(payload.eventType, payload.new)
  })
  .subscribe()

What you get

Changes, broadcast and presence

Postgres changes

Add a table to the built-in stitchdb_realtime publication and receive inserts, updates and deletes.

Broadcast

Send ephemeral messages on channels — cursors, typing indicators, game state.

Presence

Track and sync who is connected with track() and presenceState().

How it works

Get started with Realtime

  1. Publish a table

    alter publication stitchdb_realtime add table public.todos;

  2. Subscribe

    stitchdb.channel('todos').on('postgres_changes', …).subscribe()

  3. Send from SQL

    select realtime.send('{"status":"shipped"}'::jsonb, 'order-update', 'orders', false); inside a trigger.

JavaScript
const room = stitchdb.channel('room-1')

room.on('broadcast', { event: 'cursor' }, ({ payload }) => moveCursor(payload))
await room.subscribe()

room.send({ type: 'broadcast', event: 'cursor', payload: { x: 120, y: 48 } })

Example

See it in code

const room = stitchdb.channel('room-1')

room.on('broadcast', { event: 'cursor' }, ({ payload }) => moveCursor(payload))
await room.subscribe()

room.send({ type: 'broadcast', event: 'cursor', payload: { x: 120, y: 48 } })

Start building on StitchDB today

Create your first project in under a minute.