Return to the SharedCounter lesson

SharedCounter live lab

Complexity Intermediate

Open one room across three tabs or devices. You control one hiker and compare the local notebooks as you exchange updates.

Create or join a room

Create a room, then open its link in two more tabs or on two other devices. The first three connections control the hikers; further connections observe.

The room service numbers signed changes, stores each operation, and broadcasts it. Your browser applies the numbered stream through the counter kernel.

Enable JavaScript to connect to a live room.

  • AliceJoin to check
  • BobJoin to check
  • CarolJoin to check

Your browser's local notebooks

Your assigned notebook has the controls. The other two are local copies in this browser, not views into the other devices.

Application rule Apply each sequence number once, in sequencer order.

Unnumbered note In transit to the ranger

Stamped copy Being delivered to every hiker

Alice

Agreed count received

Local copy in this browser

10

Birds in this hiker's view

Bob

Agreed count received

Local copy in this browser

10

Birds in this hiker's view

Carol

Agreed count received

Local copy in this browser

10

Birds in this hiker's view

Ranger sequencer SN 0 stamp · broadcast
  1. No signed change sequenced yet.
Optional: local delivery model

Speed, Jitter, and Auto-deliver affect delivery among the three copies in this browser. They do not pause the WebSocket connection or the server's sequencing and storage. Rejoin to recover the stored log.

Enable JavaScript to run the demo. The numbered example and final result remain available in the article.

Send a signed change, or race Alice's count against Bob's correction.

Open the sequence-number rule

A network can repeat a stamped copy. Each hiker records the sequence numbers they have applied and ignores repeated copies.

        next SN → apply remote delta or acknowledge own edit
        seen SN → ignore duplicate
        missing SN → hold later operations and request history

The single-browser mode keeps its log in memory. Three-device mode uses durable storage for up to 1,000 numbered operations. Rejoining replays that log from the agreed count of 10. Auto-deliver controls only local delivery animation, not the real server's sequencing or storage.

Try a concurrent update

  1. Create a room. Open its link in two more tabs, or share the link with two other devices. Check that Alice, Bob, and Carol have connected.
  2. In Alice's tab, send +3. In Bob's tab, send -1. Make both changes before comparing the notebooks.
  3. From a reset count of 10, all copies should reach 12. Compare the numbered log, then leave and rejoin to replay it.

Reset clears the shared room for all connected hikers. An observer can read the room but cannot edit or reset it.

Storage and recovery

A Cloudflare Durable Object stores this room's shared data in a private SQLite database.

The server stores numbered signed operations. Rejoining replays that log from 10; Reset clears it and restores 10. At 1,000 operations, reset the room before sending more changes.

Closing all tabs does not clear stored data. After a disconnect, rejoin to recover it. There is no persistent offline outbox or automatic reconnect; unconfirmed changes may be lost. Roles identify connections, not accounts. Anyone with the room code can join.

How multiplayer rooms work explains CRDT merging, DDS sequencing, storage lifetimes, and the example database records.