Subscriptions & Live Queries
KalamDB’s real-time engine pushes data changes to connected clients over WebSocket. This eliminates the need for polling and separate pub/sub infrastructure.
For the runtime architecture, table-type delivery behavior, and cluster fan-out path, see /docs/server/architecture/live-query.
SUBSCRIBE TO
Subscribe to a table for real-time change notifications:
Options
| Option | Description |
|---|---|
last_rows=<n> | Receive the last N rows as initial data |
batch_size=<n> | Maximum rows per notification batch |
from=<n> | Resume from a specific sequence ID |
Examples
KILL LIVE QUERY
Cancel an active subscription:
Using Subscriptions via SDK
The recommended way to use real-time subscriptions is via the TypeScript SDK:
Using Subscriptions via CLI
In the interactive CLI, use \live or \subscribe:
Both forms start the same live query flow. Press Ctrl+C to stop the subscription.
How It Works
- Client sends a
SUBSCRIBE TOstatement (via SQL, SDK, or WebSocket) - KalamDB registers the subscription with filter conditions
- On every
INSERT,UPDATE, orDELETEmatching the filter, a change event is pushed - Events are delivered over the persistent WebSocket connection
- Client can cancel with
KILL LIVE QUERYor disconnect
UPDATE notification payload
For UPDATE events, the notification includes:
rows: All non-null columns from the updated row, plus the primary key and_seq. This provides a full snapshot of the current row state without requiring a re-query.old_values: Only the columns that actually changed (plus PK and_seq), with their previous values.
This design makes tables usable as change triggers — when any column is updated, subscribers receive every non-null value, not just the diff.