# Realtime

> Realtime delivers Postgres changes, broadcast and presence over WebSockets. An instance belongs to a database and uses Infaris Auth.

Source: https://docs.infaris.com/en/pulseguard/hosting-realtime

## What it is

Realtime delivers Postgres changes, broadcast and presence over WebSockets. An instance belongs to a database and uses Infaris Auth.

## Quick start and CLI

```bash
infaris-guard hosting db realtime set <databaseId> --enabled --auth-project <projectId> --tables '[{"schema":"public","table":"todos"}]'
infaris-guard hosting db realtime tables <databaseId>
infaris-guard hosting db realtime lint <databaseId>
bun add @infaris/realtime-js
```

## SDK and code

```ts
import { createRealtimeClient } from '@infaris/realtime-js';
const rt = createRealtimeClient({
  url: process.env.NEXT_PUBLIC_INFARIS_REALTIME_URL!,
  apiKey: process.env.NEXT_PUBLIC_INFARIS_AUTH_KEY!,
  accessToken: () => auth.getAccessToken(),
});
const channel = rt.channel('todos');
channel.on('postgres_changes', { event: '*', schema: 'public', table: 'todos' }, console.log);
channel.subscribe();
// On cleanup: await rt.removeChannel(channel);
```

## Secure defaults

Channels are private. Create SELECT and INSERT policies on `realtime.messages` for receiving and sending. Postgres changes follow the subscriber’s SELECT policy and column privileges. Never use a secret key in the browser.

## Limits

Per instance: 1,000 connections, 100 channels per connection, 256 KiB payload and 500 Postgres changes per second. Changes above the limit may be dropped. Persisted broadcasts last 24 hours. Realtime is not a durable queue.

## FAQ

**No events?** Check publication, policies and token. **Disconnected?** The SDK reconnects, but reload critical database state. **Let everyone join?** Public channels require explicit enablement; a key alone does not make a channel public.
