Serverless WebSockets: what an idle connection costs on AWS, Vercel, Cloudflare and CrabTalk
A WebSocket mostly sits idle. How API Gateway, Vercel, Durable Objects, containers and CrabTalk bill an open connection between messages, with dated sources.
CrabTalk Team
A WebSocket connection spends almost all of its life waiting. A chat client, a live dashboard or an agent watching a board sends a message every few seconds or minutes and holds the connection open in between. On a serverless platform, the question that decides the bill is who holds that connection between messages, and whether your code's memory is billed while it does. This post compares how the main platforms answer it, and how CrabTalk serves WebSockets so that an idle connection holds no memory of your service.
Who holds the connection between messages
| Platform | Between messages | What you pay for | Source |
|---|---|---|---|
| AWS API Gateway with Lambda | API Gateway holds the connection; each message invokes a function | Connection minutes and messages, plus each Lambda invocation. AWS's US East example uses $0.25 per million connection minutes and $1.00 per million messages, metered "in 32KB increments" | API Gateway pricing |
| Vercel Functions | The function instance holds it, on Fluid compute (public beta) | Provisioned memory "for the lifetime of the instance": "an open connection keeps its instance's memory billable until the connection closes". Connections close at the function's maximum duration, 300 s on Hobby and 800 s on Pro | Vercel WebSockets |
| Cloudflare Durable Objects | Cloudflare's network holds it while the object hibernates | Nothing while idle: "Billable Duration (GB-s) charges do not accrue during hibernation". Incoming messages are billed as requests at 20 to 1; outgoing ones are free | WebSockets, pricing |
| Containers, such as Render | Your process holds it, for as long as the instance runs | The instance, whether or not messages arrive. Render's connections last "until the connected instance shuts down" | Render WebSockets |
| CrabTalk | The host holds it; your service runs only for each event | Each event as a call: opening counts one run, and messages pay only the CPU, memory and rows they use. An idle connection holds no memory of your service | WebSockets |
Pages read November 29, 2026.
Two designs keep an idle connection cheap: a gateway that holds the socket and invokes code per message (API Gateway), and a runtime that evicts the code but keeps the socket (Cloudflare's hibernation). Both separate the connection from the code. Platforms that keep the code holding the socket, a Vercel instance or a container, bill its memory or its machine for the whole connection.
How CrabTalk serves a WebSocket
A CrabTalk service is a Rust crate compiled to WebAssembly, and each call runs in a fresh instance that holds memory only while it runs. That is already the shape hibernation gives a Durable Object, so WebSockets needed no new execution model: the host holds the socket, and each thing that happens on it is a call.
A service marks one tool as a socket tool. The host calls it once per event, in order:
use berm_lang::{Result, socket::{self, Event}, tool};
/// Keeps a room of connections
#[tool(socket)]
pub fn room(event: Event) -> Result<()> {
let mut room: Vec<String> = berm_lang::get("room")?.unwrap_or_default();
match event {
Event::Open { connection } => room.push(connection),
Event::Message { data, .. } => {
let all: Vec<&str> = room.iter().map(String::as_str).collect();
socket::send_all(&all, &data)?;
}
Event::Close { connection, .. } => room.retain(|held| *held != connection),
}
berm_lang::set("room", &room)?;
Ok(())
}Open, eachMessage, thenClose, each as a call by whoever opened the connection, so the tool's access rules decide who may connect. A tool that fails onOpenrefuses the connection.- Sending reaches one connection, several at once, or closes one. A service can send only to its own connections.
- State lives in the service's storage, keyed by connection ID. Nothing is held in memory between events, so there is no attachment size limit to work around and nothing is lost when the code is reloaded.
- A deploy does not drop connections. The host keeps the socket, and the next message runs the new version.
Clients connect at wss://{owner}.crabtalk.app/{service}/sockets/{tool}, or on the local host at ws://127.0.0.1:7777/services/local/{service}/sockets/{tool}. The WebSockets guide covers connecting, and WebSockets in code the tool itself.
What an idle connection costs
Nothing on CrabTalk, as on a hibernating Durable Object: between events no call runs, so no memory of the service is held or billed.
A message is a call without a run charge. It pays for the CPU it spends, the memory it holds while it runs and the rows it reads and writes, at the list rates on Pricing. A message holds its tool's memory budget, 8 MB by default, only for the milliseconds it runs, where a Durable Object woken by a message is billed 128 MB for as long as it stays in memory. We will publish a per-message comparison once a real service carries WebSocket traffic and we can measure it, rather than estimate it here.
What it does not do yet
- Messages are text. A binary message closes the connection.
- Browsers connect with no sign-in. A browser's WebSocket cannot send an
Authorizationheader, so a browser reaches a socket tool declaredaccess = "anonymous"with no sign-in. Servers, agents and CLIs sign in with a bearer token. - Each node holds a fixed number of connections across the services it runs, and refuses one past it with a clear error. A node restart closes its connections, and clients reconnect.
- MCP does not use it. Remote MCP runs over Streamable HTTP, and every CrabTalk service keeps serving its own MCP server as before. WebSockets are for clients that want a live connection: live boards, chat, dashboards and agents that watch for changes.
Try it
Run the local host with crab dev, deploy a service with a socket tool, and connect from any WebSocket client. The WebSockets guide has the URLs and the sign-in for each place a service runs.