Skip to main content
PocketBase includes built-in realtime capabilities using Server-Sent Events (SSE), allowing clients to receive live updates when records are created, updated, or deleted.

How realtime works

The realtime system uses a publish-subscribe pattern:
  1. Clients connect via SSE to /api/realtime
  2. Clients subscribe to specific collections or records
  3. Server broadcasts events when data changes
  4. Clients receive updates in real-time

Subscription topics

Clients can subscribe to different topics:

Collection subscriptions

Record subscriptions

Wildcard subscriptions

Wildcard subscriptions can be resource-intensive. Use them sparingly and consider implementing server-side limits.

Realtime events

Three types of events are broadcast:

CREATE event

Triggered when a new record is created:

UPDATE event

Triggered when a record is updated:

DELETE event

Triggered when a record is deleted:

Server-Side Events (SSE) connection

Realtime uses SSE for client-server communication:

Connection lifecycle

Connection properties

Client identification

Each connection gets a unique client ID:
Clients must send this ID when subscribing to topics.

Managing subscriptions

Setting subscriptions

Clients send a POST request to update their subscriptions:
Each subscription request replaces all previous subscriptions for that client. To unsubscribe from everything, send an empty array.

Subscription validation

Subscription limits

  • Maximum subscriptions per client: 1000
  • Maximum subscription topic length: 2500 characters
  • Client ID length: 1-255 characters

Authentication and authorization

Auth state management

Realtime respects authentication state:

Auth upgrades

Clients can upgrade from guest to authenticated:
Clients cannot switch between different authenticated users without reconnecting. Auth downgrades (from authenticated to guest) are also forbidden.

API rules apply

Realtime events respect collection API rules:
If a client doesn’t have permission to view a record, they won’t receive realtime events for it.

Server-side implementation

Broadcasting custom events

Sending to specific clients

Managing client state

Iterating over clients

Realtime hooks

Message hooks

Connection hooks

Subscription hooks

Connection management

Idle timeout

Connections timeout after inactivity:

Connection limits

Implement connection limits:

Graceful disconnection

Client libraries

PocketBase provides official client SDKs with realtime support:

JavaScript/TypeScript

Dart/Flutter

Performance considerations

Subscribe only to the collections and records you need. Overly broad subscriptions waste bandwidth and processing power.
If you’re making multiple record changes, consider batching them to reduce the number of realtime events.
For high-frequency updates, throttle or debounce client-side handlers to avoid UI performance issues.
Track active realtime connections and implement limits to prevent resource exhaustion.
Enable HTTP compression on your reverse proxy to reduce bandwidth usage for realtime connections.
Always unsubscribe when components unmount or views change to prevent memory leaks.

Debugging realtime

Enable debug logging

Monitor active connections

Test with curl