rhocfsandbox.com

demo: durable objects live viewer count

open this page in multiple tabs (or share the url with a friend). every open tab holds a websocket to the same durable object, which broadcasts the current connection count to all listeners in real time.

viewers connected right now
connecting…

# how it works

  1. page opens a websocket to wss://site-livecount-do.rhomanie-demo-account.workers.dev/ws
  2. the worker forwards the upgrade to a durable object stub keyed by global
  3. the DO accepts the ws, adds it to an in-memory Set, and broadcasts {count} to all sessions
  4. on close/error, the DO removes the session and rebroadcasts
  5. every visitor talks to the same DO instance because the id is derived from a fixed name

# why not just workers?

workers are stateless. two requests can land on different workers with no shared memory. durable objects give you a single-threaded actor with strongly consistent in-memory state, pinned to one region. perfect for coordination like counters, chat rooms, game lobbies, presence.