Real-time listen
A genuine server-sent-event stream backed by Supabase Realtime, with keepalives, reconnection inside the platform’s time limit, and a polling fallback.
const subscription = client
.listen('*[_type == "post"]')
.subscribe((update) => {
console.log(update.transition, update.documentId)
})The stream is real: a mutation committed anywhere — the Studio, a script, another instance — produces an event. It is backed by Postgres change events delivered through Supabase Realtime, not by polling.
What a serverless platform forces
Two constraints, and both are handled rather than hidden:
- Functions have a time limit. The stream sends keepalives and closes cleanly before it, and the client reconnects. A listener that silently stops after a few minutes is worse than one that never started.
- Concurrent connections are capped, especially on a free tier. When a stream cannot be held, the client degrades to polling rather than erroring.
What an event carries
The transition (appear, update, disappear), the document id, the transaction id, and — when asked for — the document itself. Filtering is by GROQ, evaluated against the change.
