Repository navigation
Releases
Releases · upstash/realtime
v1.2.1
Emits no longer lock the whole database
emit()locks only its channel. The emit script now declaresallow-key-locking, so Upstash holds a lock on the channel's key while the script runs instead of the database-wide lock. Other commands on your database no longer wait for an emit, and Upstash can run emits to different channels in parallel, up to your plan's parallelism.- Order is unchanged. Emits to one channel still run one after another, so delivery order keeps matching stream order.
Upgrading
- No code changes. Events are stored and published exactly as in 1.2.0, and instances on 1.2.0 and 1.2.1 can run side by side.
emit()needs an Upstash database. Stock Redis, for example behind SRH, rejects the script withERR Unexpected flag in script shebang: allow-key-locking.
Full change: c867c14
v1.2.0
Faster, with far less load on Redis
emit()takes one round trip instead of two. An event is stored and published by one script call. In our tests emit latency halved (211 ms to 105 ms on a distant database, 54 ms to 26 ms on a nearby global one).- Connections share Redis subscriptions. The SSE connections one instance serves now share one Redis subscription per channel, instead of each opening their own. For 1,000 clients on a channel that is one subscription instead of 1,000, and about 19x less CPU per delivered event on Node.
- The keepalive only pings idle channels. Before, every connection published a ping every minute and every connection on the channel received each of them. Now a channel gets about one ping per idle minute in total.
- Server-side
subscribe()stops its keepalive when unsubscribed. Before, each closed subscription kept publishing a ping every minute. - The client reconnects only when its channels change. A hook mounting or unmounting no longer replaces the connection, and events a hook already received are not delivered again.
- A subscription that silently stops receiving is noticed within about a minute, and clients resume from their last event.
Upgrading
- Requires
@upstash/redis1.36.1 or newer. Older versions lose subscription messages that span two network reads. emit()refuses events over 1,000,000 characters, which could not be delivered.- Channel names the Redis SDK cannot subscribe to (containing
/,\,?,#,%or a comma) are served from history only by the handler; server-sidesubscribe()rejects all of those except a comma. - Error frames sent to clients carry fixed text; the details stay in the server log.
Full change: #30
v1.2.0-canary.0
Canary of the performance work on josh/realtime-perf.
emit()stores and publishes an event in one round trip instead of two- SSE connections served by one instance share a Redis subscription per channel
- The keepalive pings a channel only when it has been idle
- The client reconnects only when its set of channels changes, and drops events it already delivered
- Server-side
subscribe()stops its keepalive when unsubscribed emit()refuses events over 1,000,000 characters, which could not be delivered- Requires
@upstash/redis1.36.1 or newer
Install with npm install @upstash/realtime@canary.
v1.1.1
What's Changed
- DX-2984: bundle Realtime source and docs by @ytkimirti in #28
New Contributors
- @ytkimirti made their first contribution in #28
Full Changelog: v1.1.0...v1.1.1
v1.1.1-canary.0
v1.1.0
Cursor-based resumption for server-side subscriptions
Every event delivered by a server-side subscribe() now carries an opaque cursor. Pass the last handled cursor back as after to resume exactly where you left off — missed events are replayed from the stream, then live delivery continues with automatic deduplication:
await realtime.channel("jobs").subscribe({
events: ["job.updated"],
after: storedCursor,
onData(message) {
handleJobUpdate(message.data)
saveCursor("jobs", message.cursor)
},
})- A trimmed, expired or malformed cursor rejects the subscription with the new
CursorUnavailableError, so you can reload canonical state and start fresh. afterandhistoryare mutually exclusive, enforced at the type level and at runtime.RealtimeCursoris a branded string; narrow stored values with the exportedisRealtimeCursorguard before passing them toafter.- Failed history replays now reject the
subscribe()promise and clean up the underlying Redis subscription instead of hanging. - Stream-id comparison uses
BigInt, so sequence numbers beyond 2^53 order correctly.
See docs/server-side-cursor-resumption.md for a full usage guide.
Compatibility notes
onDatapayloads gain acursorproperty, and the exportedUserEvent["id"]type is now branded — a type-level change for TypeScript consumers constructingUserEventvalues manually. Hence the minor version bump.- Event ids are now validated against the Redis stream-id format (
^\d+-\d+$) everywhere. Events published to a channel by hand (rawredis.publishwith a customid, bypassingemit()) are silently dropped from delivery. Useemit(), which mints valid ids viaXADD.
Thanks @smorimoto for the contribution (#26, closes #25).
1.0.4
What's Changed
Fixes
- Prevent event loss during history replay (#24, fixes #23):
subscribe({ history: true })could silently drop events published while theXRANGEhistory replay was in flight, because the pub/submessagelistener was only registered after replay finished. Listeners are now registered up front; live events arriving during replay are buffered, delivered after the historical entries, and deduplicated against the last replayed stream id — including on the post-replay pub/sub path, sinceemitrunsXADDbeforePUBLISHand the same event can arrive through both. - Fixed a leaked ping interval when a subscriber unsubscribes while history replay is still running.
Internal
- Added a
bun testregression suite covering the replay race, both deduplication paths, and the unsubscribe-during-replay case.
Thanks @smorimoto for the report and fix!
Full Changelog: v1.0.3...v1.0.4
1.0.3
Upstash Realtime 1.0 Canary
1.0 Canary version for Upstash Realtime