Watch
Get notified in real time when a key or namespace changes.
Watching in Litebase lets you subscribe to key or namespace changes as they happen. This is useful for reactive systems, configuration updates, cache invalidation, live dashboards, and more.
Rather than polling for changes, you can listen for real-time updates — every write, version bump, or new value is delivered as a push.
1. What can you watch?
You can watch:
- A single key: e.g.
user.abc123.profile - A key prefix (namespace): e.g.
user.abc123.orproject.42.
Whenever a matching key is written, you’ll receive an event with the new version’s metadata and value.
2. Connect to a watch stream
To start watching, connect via Server-Sent Events (SSE):
You can also watch a single key:
3. Receive change events
Each time a matching key is updated, you’ll receive an event like:
Parse the data: line as JSON to get the full change payload.
4. Resume from a known point
To avoid missing updates after a disconnect, you can resume from a known transaction using the since parameter:
This will replay any missed changes and continue watching in real time.
5. Use cases
Watching is ideal for:
- Live UIs that reflect real-time changes
- Distributed agents reacting to new configs
- Async workers waiting on status updates
- Monitoring or audit systems observing key changes
- Cache invalidation based on actual writes
Because all values are versioned and timestamped, you can react with confidence.