# WebSocket Hibernation

URL: https://eoxlabs.dev/glossary/websocket-hibernation
Last updated: 2026-11-26
Publisher: EOXLABS (https://eoxlabs.dev)

Section: [Glossary](https://eoxlabs.dev/glossary)

WebSocket hibernation is a feature of Cloudflare Durable Objects that lets an object be evicted from memory while its WebSocket clients stay connected. The connections remain open on Cloudflare's network. When a message arrives, the runtime re-creates the object, runs its constructor again and delivers the message to the object's handler.

## Why does hibernation change the economics of real-time features?

Presence indicators, live notifications and inboxes hold connections open for hours while messages are sparse. Without hibernation, the Durable Object serving those sockets stays resident the whole time. Cloudflare's guide to [WebSockets in Durable Objects](https://developers.cloudflare.com/durable-objects/best-practices/websockets/) states that "Billable Duration (GB-s) charges do not accrue during hibernation". For a product with many mostly idle connections, hibernation removes the cost of keeping objects in memory between messages.

## How does EOXLABS build with hibernating WebSockets?

The rules below come from the platform's documented behavior, and EOXLABS applies them to every hibernating object it designs:

1. Accept connections with `ctx.acceptWebSocket()`, not `ws.accept()`. Only the former allows the object to hibernate.
2. Keep per-connection state small and store it with `serializeAttachment()`, which Cloudflare caps at 16,384 bytes. Larger data goes to the object's storage, with only its key attached to the socket.
3. Keep the constructor light, because it runs again after every wake-up.
4. Avoid `setTimeout` and `setInterval` for idle housekeeping. Cloudflare lists timers, alarms and incoming requests among the events that keep an object awake.

The engineering note on a [real-time inbox built with WebSocket hibernation](https://eoxlabs.dev/engineering/websocket-hibernation-realtime-inbox) puts these rules to work.

## What does it look like in practice?

A support team keeps an inbox tab open all day, and a new ticket arrives every few minutes. Between tickets, the Durable Object holding the team's sockets hibernates. Protocol-level ping frames, defined in [RFC 6455](https://www.rfc-editor.org/rfc/rfc6455), are answered by the runtime without waking the object. A new ticket wakes it, the object reads each socket's attachment to learn who is connected, and it pushes the ticket to the right agents. The wake-up adds a little work to the first message after a quiet period, which can show up in tail latency.

## What is hibernation often confused with?

- **Disconnection.** Clients see no close event during hibernation. If either side does close the connection, its attachment is lost.
- **Persistence of memory.** In-memory state is reset on eviction. Anything held only in variables is gone when the object wakes.
- **Outbound connections.** Cloudflare states that hibernation "is only supported when a Durable Object acts as a WebSocket server" and that "Outgoing WebSockets do not hibernate." An object holding an outbound connection to a speech or streaming provider does not hibernate; Cloudflare notes that an open outbound WebSocket "prevents eviction for up to 15 minutes", which matters for [real-time voice systems](https://eoxlabs.dev/capabilities/real-time-voice).

The platform underneath is described on the [Durable Objects stack page](https://eoxlabs.dev/stack/durable-objects), and the [glossary](https://eoxlabs.dev/glossary) defines related terms.

## Related

- [WebSocket hibernation for a real-time inbox](https://eoxlabs.dev/engineering/websocket-hibernation-realtime-inbox): One Durable Object per inbox, hibernating WebSockets, messages written to SQLite before fan-out, and a sequence cursor that lets a reconnecting device replay exactly what it missed.
- [Durable Objects](https://eoxlabs.dev/stack/durable-objects): Durable Objects give EOXLABS one single-threaded, authoritative home for each piece of shared state, with clear guarantees, hard limits and cases where another store is better.
- [Durable Object](https://eoxlabs.dev/glossary/durable-object): A Durable Object is a single-threaded Cloudflare Worker with a unique name and private, strongly consistent storage. It gives edge systems one place to coordinate each piece of state.
- [Real-Time and Voice Systems](https://eoxlabs.dev/capabilities/real-time-voice): EOXLABS designs live features (chat, presence, live dashboards, calls and voice agents) with WebSockets held by Durable Objects for state and Cloudflare Realtime for WebRTC media.

## More glossary

- [Envelope Encryption](https://eoxlabs.dev/glossary/envelope-encryption)
- [Immutable Backup](https://eoxlabs.dev/glossary/immutable-backup)
- [WORM Storage (Write Once, Read Many)](https://eoxlabs.dev/glossary/worm-storage)
