Realtime
EdgeBase Realtime enables live data synchronization over WebSocket connections. Subscribe to database queries and receive automatic updates when data changes, track which users are online with presence channels, and broadcast arbitrary messages between clients. Connections use Cloudflare's Hibernation API — idle WebSockets cost $0 and wake instantly when new data arrives.
Features
Subscriptions
onSnapshot — live query results that update automatically when data changes
Presence
Track who's online per channel with custom metadata
Broadcast
Send arbitrary messages to all connected clients on a channel
Access Control
Channel rules with wildcard patterns, JWT re-evaluation, instant kick
Hibernation-Aware
Idle WebSockets cost $0 — automatic RESYNC recovery on wake-up
What Can You Build?
- Live Dashboards — Subscribe to database tables and update charts, metrics, and feeds in real time
- Chat Applications — Broadcast messages between users with presence indicators showing who's online
- Collaborative Editors — Track cursor positions with Presence and relay keystrokes with Broadcast
- Multiplayer Games — Synchronize player states and game events across clients (or use Room for server-authoritative state)
Which Primitive Should You Use?
Most confusion comes from the fact that Realtime includes three primitives, and they sit next to Room and Push Notifications elsewhere in the docs.
- Use Subscriptions when the source of truth is the database.
- Use Presence when you need to know who is connected right now.
- Use Broadcast when you need to relay arbitrary events to connected clients.
- Use Room when the server must own and validate live state.
- Use Push when the update must reach a device outside the active realtime session.
For a full side-by-side breakdown, see Choosing Between Subscriptions, Presence, Broadcast, Room, and Push.
How it Works
Client A ── subscribe('posts') ──▶ RealtimeDO (WebSocket)
│
Client B ── insert(post) ──▶ DatabaseDO ──┘ stub.fetch() — direct DO-to-DO
│
┌────┘ (dual propagation)
│
Client A ◀── table channel ────────┤ (realtime:shared:posts)
Client C ◀── document channel ─────┘ (realtime:shared:posts:post-id)- Client subscribes to a query via WebSocket
- When any client modifies matching data, the DatabaseDO notifies the RealtimeDO via direct
stub.fetch()(no Worker hop) - Events are pushed to both table-level and document-level subscribers simultaneously (dual propagation)
Connections use Cloudflare's Hibernation API — idle WebSockets cost $0 and wake instantly on new messages.
Quick Example
// Subscribe to live query results
const unsubscribe = client.db('shared').table('posts')
.where('status', '==', 'published')
.orderBy('createdAt', 'desc')
.limit(20)
.onSnapshot((result) => {
console.log('Live posts:', result.items);
});
// Track online users
const presence = client.realtime.presence('chat-room');
presence.track({ name: 'Jane', status: 'online' });
presence.onSync((users) => console.log('Online:', users));
presence.onJoin((userId, connId, state) => console.log(`${userId} joined`));
presence.onLeave((userId) => console.log(`${userId} left`));
// Broadcast a message
const channel = client.realtime.channel('chat-room');
channel.send('message', { text: 'Hello everyone!' });
channel.on('message', (payload, meta) => {
console.log(`${meta.userId}: ${payload.text}`);
});
Security
- Subscriptions reuse the table's
readaccess rule (evaluated once at subscribe time) - Presence & Broadcast use
realtime.namespacesrules with wildcard pattern matching - Default policy: unauthenticated users are always denied, even in development mode
- Re-auth: when a JWT refreshes, all subscriptions are re-evaluated and unauthorized channels are auto-revoked
- Instant kick: KV blacklist for immediate session termination in emergency scenarios
- Server broadcast (via Admin SDK) bypasses channel rules; client broadcast respects them
Server-side realtime broadcast is available across all Admin SDKs.
EdgeBase Realtime is ~300× cheaper than alternatives at scale. At 900M fan-out messages/month: Supabase ~$2,263, Firebase ~$5,400, Ably ~$2,250 — EdgeBase ~$7. This is structural, not promotional: Cloudflare counts 20 incoming WebSocket messages as 1 DO request, outgoing messages are free, fan-out happens inside the DO with no per-recipient billing, and idle connections cost $0 via the Hibernation API. See the full cost breakdown.
Maturity
All Realtime features — Subscriptions, Presence, and Broadcast — are Generally Available (GA). The protocol, API surface, and billing model are stable.
Next Steps
onSnapshot, event types, batch delivery
AND/OR filters, operators, runtime updates
Online tracking, events, auto-cleanup
Pub/sub messaging, server broadcast, REST API
Channel security, re-auth, instant kick
Channel-DO mapping, protocol, error codes
Settings reference and limits