Getting Started
Tutorial: Building with CleaveDB
Real-time Pub/Sub (LISTEN) — Overview
Modern interactive applications—such as live collaborative editors, instant messaging, financial tickers, and multi-user dashboards—require immediate updates when data changes. Instead of maintaining external message brokers like Redis Pub/Sub or third-party web socket services, CleaveDB turns directly into a real-time event broker using LISTEN.
Three Subscription Models
1. Bucket Subscriptions
Stream all write and modification events occurring anywhere within an entire bucket (e.g. LISTEN TO chat).
2. Document Subscriptions
Listen exclusively to changes targeting a specific document ID (e.g. LISTEN TO users "david").
3. Live Computed Feeds
Combine ENRICH with LISTEN to push documents with pre-computed formulas and virtual metrics on write.
Real-Time Architecture Highlights
- Direct In-Engine Dispatch: Mutation events are intercepted inside the query execution cycle, ensuring sub-millisecond broadcast latency.
- Connection-Level DLS Enforcement: Broadcasted events automatically honor Data-Level Security (DLS) policies matching the connected client's authenticated role.
- Multi-Client Scaling: Lightweight asynchronous event dispatchers support thousands of concurrent connected subscribers without database performance degradation.
Explore the Real-Time Topics
Review the guides below to build reactive real-time architectures:
