one durable object per room or one DO plus a KV index for 500 live rooms Durable Objects
Collaborative editor. Expect up to 500 rooms active at once, 2 to 20 people each, WebSockets, and the document state per room is small — tens of kilobytes.
I keep going back and forth. One DO per room feels like the intended design but 500 objects sounds expensive and I cannot find a clean way to list them. One central DO with a KV index is easier to reason about but obviously has a single-thread problem somewhere. This is a side project so the bill matters.
@first_repo_finn · 4mo ago · 3 replies
One per room, without hesitation. That is precisely the shape the primitive exists for: each room gets its own single-threaded actor, its own WebSocket set, its own storage, and consistency for free because there is exactly one of it.
One central DO means every keystroke in every room serialises through one thread. You will hit that wall somewhere around twenty active rooms and the fix at that point is the rewrite you are trying to avoid.
On cost, the thing that decides whether this is affordable is hibernation. Use
state.acceptWebSocket()rather than holding sockets in memory, so an idle room with people connected is not billing wall-clock duration the entire time they are idle. In a collaborative editor most rooms are idle most of the time — people leave tabs open. Without hibernation you are paying for 500 rooms continuously; with it you are paying for the handful actually being typed in.Listing rooms is a separate problem and should not influence this. Keep room metadata in D1 and let the DOs handle only live state.
Reply
Report
@visa_run_val · 4mo ago
"Listing is a separate problem" is the part I had tangled up. I was picking a live-state architecture based on wanting a room list on a dashboard.
Reply
Report
@deploy_friday_ok · 4mo ago
Hibernation is the entire ballgame for anything socket-shaped. Three idle users in a room look identical to three active ones from a billing perspective if you hold the sockets yourself, and that difference is the whole reason people post "why is my DO bill like this".
Reply
Report