Skip to content

docs: document upgradeWebSocket and rework cross-isolate messaging - #5484

Open
philip wants to merge 5 commits into
mainfrom
docs/functions-websocket-upgrade
Open

docs: document upgradeWebSocket and rework cross-isolate messaging#5484
philip wants to merge 5 commits into
mainfrom
docs/functions-websocket-upgrade

Conversation

@philip

@philip philip commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Overview

Expands the WebSockets and SSE guide to cover upgradeWebSocket from @neon/functions and to
rethink cross-isolate messaging for scale-to-zero.

Serve a WebSocket

Lead with upgradeWebSocket (open the socket from your fetch handler, no extra export and no
ws dependency), alongside the existing upgrade export for raw-socket cases. Adds a Hono
example that runs the handshake through route middleware, subprotocol selection, and a note
distinguishing the three same-named upgradeWebSocket functions by package.

Cross-isolate messaging

Recommends polling Postgres by default so functions keep scaling to zero, with LISTEN/NOTIFY
reserved for always-on compute that needs sub-second latency.

Also

cli/dev.md: neon dev serves WebSocket upgrades locally. Removes the stale note claiming
neon dev returns 200 for upgrades.

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
neon-next Ready Ready Preview Sep 1, 2026 5:57pm UTC

Request Review

philip and others added 4 commits September 1, 2026 10:42
A refused handshake's status and body don't reach a WebSocket client, so drop the
claim that a returned Response arrives intact. Note instead that the client sees only
a generic connection failure, and to send any detail it needs over a separate
authenticated request.

Co-authored-by: Isaac <no-reply@databricks.com>
Lead with upgradeWebSocket for new functions and cover its real behavior: the standard
WebSocket it returns, when it throws, subprotocol selection, and refusing a handshake.
Reorganize cross-isolate messaging around polling as the default, which keeps scale to
zero, with LISTEN/NOTIFY for always-on compute, and add a complete polling example.
Correct the heartbeat, binaryType, and refusal notes. The examples were verified under
neon dev and against a live database.

Co-authored-by: Isaac <no-reply@databricks.com>
Guard each send with readyState === OPEN so a socket that is mid-close does not throw
and abort the poll cycle, which would skip that row for the remaining clients.

Co-authored-by: Isaac <no-reply@databricks.com>
@philip philip reopened this Sep 2, 2026
@philip philip changed the title docs: document upgradeWebSocket on Neon Functions docs: document upgradeWebSocket and rework cross-isolate messaging Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant