WebRTC

Understanding WebRTC by comparing it with WebSocket. This article covers signaling, connection establishment with ICE, STUN, and TURN, and data transport through DataChannel and Media.

October 13, 2026 | 3 min

Durable Object Hibernation Keeps the WebSocket and Drops Every Class Field

Cloudflare’s docs say hibernation keeps WebSocket connections open and discards in-memory state. This post runs a small Durable Object under local workerd and watches exactly what that means: the socket stays OPEN, the constructor runs again on the next message, class fields reset, attachments survive only if you serialize them, and a pending timer or the standard WebSocket API quietly turns hibernation off. Production behaviour and billing are not tested.

September 22, 2026 | 13 min

Waiting for bufferedAmount Protects the Sender, Not a Slow Consumer

WebSocket send() never waits, and bufferedAmount only sees the part of the path that is in your own process. In a small lab, a sender that politely waited for bufferedAmount to drain still let a slow consumer queue nearly all 400 messages in its own memory, while a credit window of 8 kept the backlog at 8. This post goes through four common beliefs about send(), bufferedAmount, message size and backpressure, tests each one, and ends with a table for choosing between them.

September 6, 2026 | 14 min

A WebSocket Stays Open After Its Token Expires

A WebSocket carries credentials once, at the handshake, and afterwards the server holds only a verdict. When the token expires or is revoked, the open socket does not change. The Origin header checked at the handshake is the browser’s statement about which page opened the socket, not proof of who is connecting. A small server that enforces expiry itself, accepts renewals under four rules, and checks Origin by exact match while always requiring a separate credential, with tests and a headless Chrome check.

August 21, 2026 | 13 min

Sending Fewer Messages over a Metered Relay

On Cloudflare Durable Objects, incoming WebSocket messages are billed and outgoing ones are not. On a relay like that, the number of messages is something you design. Three ways, with working code and tests: batch events into one frame by time, count and bytes; replace timer polling with change subscriptions and keep the poll as a fallback; and have an idle host drop its connection when nobody needs it.

August 19, 2026 | 10 min

Finding a WebSocket Whose close Never Comes, from a Phone App

A client that waited for its own socket’s close event before cleaning up stopped silently when the event never arrived. A WebSocket’s close event and readyState only tell you what the socket last reported. Three habits follow, each with working code and tests: clean up the moment you decide to close, probe only a quiet connection with an application-level ping, and on returning to the foreground, check, rebuild and catch up.

August 17, 2026 | 15 min