Durable Objects — Part 2. One door per chat room

Rule of thumb for chat: one Durable Object per room. Names like lobby or dm-alice-bob are addresses.

The Worker is the doorman: authorize, getByName(roomId), then hand off WebSocket or RPC. The room owns SQLite history and broadcast.

Why per room

One DO for every room is a global bottleneck. Per-room shards load and failure domains — the coordination atom.

Sketch

Create tables in the constructor; sendMessage persists then invalidates cache. Disk first, memory second.

ctx.id.name tells the room its own name — even inside alarm() with no caller.

Part 3: what happens when the room goes quiet — hibernation.