01 // What it’s for
Why reach for DurabilitySocket
Use DurabilitySocket to wire browser or edge clients straight into a Durable Object over Cloudflare Hibernatable WebSockets—exposing an explicit schema-validated inbound RPC surface while broadcasting sequenced outbound events that reconnecting clients can replay cleanly.
02 // How it works
Inside your Durable Object
- 01Zero-wakeup hibernation standby: Connection metadata, channel, and subscriptions are serialized onto each WebSocket attachment via
ctx.acceptWebSocket; the runtime answers heartbeats without waking an idle DO. - 02Strict inbound allowlist: Every client RPC must match a declared
inboundhandler and pass schema validation before touching object state; unknown methods are rejected at the band-pass filter. - 03Bounded replay buffer: Outbound events persist in
durability_socket_eventswith monotonic sequence numbers so briefly disconnected clients catch up seamlessly. - 04Explicit resync signal: When older events are trimmed past a reconnecting client's cursor, the socket signals a clean
RESYNCinstead of silently dropping gaps.
Storage
durability_socket_events
Hibernation
0 DO wakeups on ping/pong
Import
durability/socket