Next.js has no WebSocket API, so Vercel added upgradeWebSocket() to @vercel/functions 3.10.0. Getting an echo server running takes minutes; a chat or presence feature that works across instances and deploys needs four more pieces. A build order for a production-ready Next.js realtime feature on Vercel.
In a Next.js route handler, a GET that returns upgradeWebSocket((ws) => { ... }) from @vercel/functions (version 3.10.0 or later) accepts a WebSocket connection, and ws.on('message') and ws.send() work as you'd expect. That is the echo server. The rest of this post is what a real feature needs on top.
Client
Edge
Rules and limits apply to the upgrade request, not to messages.
Route handler
Pinned to one instance until the connection closes at max duration.
Shared state
The only way a message reaches sockets on other instances.
Durable store
A Next.js realtime feature on Vercel
Authenticate on upgrade: read the session from the request before accepting, and close with an error code the client understands.
Store first, then broadcast: write each message to the durable store with a sequence number, then publish it to Redis so every instance relays it to its own sockets.
Reconnect on the client with exponential backoff capped at about 30 seconds, plus random jitter, then send the last sequence number seen and replay what was missed.
Set maxDuration deliberately. Longer means fewer reconnects; shorter means old deployments drain faster. Either way the client must expect the close.
Version your messages, because for up to the max duration two deployments are talking to clients at once.
Load-test a reconnect storm: close every connection at once and watch the upgrade rate limit, Redis and your database.
We'll review your design before you write the reconnect logic, which is where most of the time goes. Free, 30 minutes.
Once a month: what changed in tech that month and what it means for you, from cloud and AI to security and the tools you build with. Every item links to its source. No sales pitch, unsubscribe in one click.
Book a free 30-minute call about it. Bring your setup and your bill; you'll leave knowing what we'd do first and roughly what it costs, whether or not you hire us.
Or keep reading
WebSockets on Vercel Functions Are Generally Available: The Limits, the Bill, and What You Still Build
Since October 20, 2026, Vercel Functions serve WebSocket connections on every plan, with Express, Hono, Socket.IO, Bun, FastAPI and Next.js. Connections close at the function's maximum duration (300 seconds on Hobby, up to 800 on Pro), each is pinned to one instance, and memory is billed while any connection is open. What that means for your design and your bill.
Read
Realtime Pricing Compared: Vercel WebSockets, API Gateway WebSocket APIs and AppSync Events
The same workload priced three ways: 1,000 users connected through the workday, 48 million messages a month. On AWS, API Gateway and AppSync Events charge about $1 per million messages and differ mostly in connection minutes and in who does the fan-out. Vercel charges almost nothing per message but bills memory for every instance holding connections. Where each one wins.
Read
As of November 2, 2026. Provided as is, for general information, and accurate to the best of our knowledge on the date shown. Not legal, compliance, tax, financial or other professional advice. Prices, limits and vendor services change; check current vendor documentation before relying on anything here. Terms of use.