← Writing

Running two ad-free board game sites on Cloudflare Durable Objects

Notes and first-month numbers from building TavlArena and Rolovia on Cloudflare Workers, hibernating Durable Objects, and commit-reveal dice.

A backgammon board and a Ludo board linked through a central green and violet dice seal with two dice below it.

In a sample of 250 recent app-store reviews of a popular Turkish tavla app that an agent classified for me in October, 137 mentioned rigged dice or cheating. I had originally set out to build a better Othello site because the ones I played on weren’t helping me learn, then asked coding agents to compare classic board games by search demand and existing site quality. Turkish tavla stood out because players kept running into full-screen ads, virtual coins, unlabelled bots, and dice they couldn’t check.

TavlArena (Turkish tavla and backgammon, in English and Turkish) went live on 27 October. Rolovia (Ludo, reusing the same Cloudflare Workers, Durable Objects, D1, Astro, and React setup) went live on 25 November.

One Durable Object per game table

Each online table runs inside its own Cloudflare Durable Object with SQLite storage and hibernating WebSockets. An eligible object can hibernate after roughly ten idle seconds while keeping its WebSockets open, rebuilding in-memory state on the next message. In a local M4 Pro spike on TavlArena before launch, waking an object took about 2.3 ms, handling a command took about 0.5 ms, and a turn averaged roughly 3 SQLite storage writes. On Rolovia, Cloudflare GraphQL metrics across two days of pre-launch staging tests (24 and 25 November) showed 1,594 requests and 41 seconds of active time for the single Lobby object, and 8,211 requests and 144 seconds across all LudoTable objects. Marginal request and duration compute for that test load came out well under a cent (excluding the $5/month Workers Paid base fee and storage writes).

Hibernation shapes how you write table code. Any pending setTimeout or setInterval prevents an object from hibernating, so every timer (move clocks, empty-room expiry, missing dice shares) gets multiplexed onto one alarm scheduler per object. Because alarms can fire more than once, every deadline handler re-reads its state from storage and stays idempotent.

I also avoided async calls between reading table state and writing it back. While Durable Objects gate storage calls, an unprotected async WebCrypto call inside a turn handler still leaves room for another WebSocket message to interleave unless you serialize every turn manually. On Rolovia, I wrote a small synchronous SHA-256 and HMAC-SHA256 implementation in TypeScript instead, tested byte-for-byte against WebCrypto across inputs from 0 to 1,000 bytes.

Checking table concurrency with TLC

On TavlArena I checked TLA+ models with TLC over the matchmaking slots (PlayerSlots.tla, bounded to 3 players across 2 and 3 tables), socket admission renewal, and match-end cleanup. Across those specs, model checking surfaced five concurrency bugs before launch.

In PlayerSlots.tla, TLC broke the OneLiveGame invariant on a race between a failed join and a rematch. When a failed join ran releaseClaim, it could demote the host’s active slot after a rematch had already rewritten that row, allowing the host to open a second live game. We turned that counterexample into a failing Worker test before fixing the query to release only rows written by that claim.

Commit-reveal dice, and what it cannot prove

Before the first roll of an online game, the server picks a 32-byte random seed and publishes a SHA-256 commitment covering the game ID, canonical settings JSON, seat IDs, and seed. Each human player’s browser then sends 32 random bytes of its own (bots send nothing, recorded openly as zeros). Roll n comes from HMAC-SHA256, skipping bytes 252 through 255 so (byte % 6) + 1 maps 42 of 252 values to each face.

When the game ends, the server reveals the seed. The browser checks that the seed reproduces the commitment it recorded before play, checks that its own 32 bytes match the final transcript, and recomputes every roll from the recorded contributions. Both games ship standalone open-source verifiers with test vectors generated independently in Python (tavlarena-dice and rolovia-dice).

Both fair-dice pages also spell out what this does not prove. Players send their random bytes in the clear after the server commits, and the server holds its seed during play. A dishonest server (or a player colluding with it) can test candidate final contributions after seeing honest shares and pick one for a favorable roll sequence. Closing that attack requires players to publish seat-bound commitments to their shares before anyone reveals, which adds a round trip to game start, and an operator could still abort an unfavorable game. I kept the single-round start and documented the limit.

Two things that did not work

Swapping React for preact/compat on TavlArena cut the Home bundle from 221 KB to 162 KB gzipped, then broke 63 of 1,246 Playwright tests. Focus stopped returning to dialog openers after closing a sheet, and chat sheets and reload undo broke in ways that were not worth chasing for 59 KB, so React stayed.

Over TavlArena’s first month (26 October to 28 November), players entered the public quick-match queue 109 times and got 0 matches (56 cancelled, 53 expired). At 30 to 40 daily visitors there probably aren’t enough players in the same pool at once, though I haven’t checked timestamp overlap to rule out a matching bug yet. On Rolovia I skipped split matchmaking queues and built one visible public rooms list instead.

First month numbers

The counts below come from production D1 counters and first-party Cloudflare Analytics Engine events (no cookies or IDs, automated test runs filtered out) as of 28 November.

Over the last seven full days (21 to 27 November), TavlArena logged 259 daily unique visitors in D1 (37 a day, counted by a daily keyed hash, up from 228 the week before) and 141 daily active players (20 a day). On 27 November, Analytics Engine recorded 116 games started and 93 games finished across all modes (a few finishes can belong to games started the day before). Across the last 21 days of device-tagged D1 visitors, 64% were on phones; across 3,062 Analytics Engine page views over 30 days, 28% were in Turkish. Since visit buckets went live on 19 November, 47% of 458 tagged visits came from returning browsers (visit_2 or higher). Most play is against the seven bot levels (864 bot games started in 30 days, using the open-source wildbg neural net compiled to 3.15 MB of brotli-compressed WASM).

Private friend rooms have been the brightest spot for multiplayer. Over the last 30 days, players created 219 invite rooms and joined 138 times in Analytics Engine, and D1 holds 146 finished online matches since launch (rematches inside a room account for finishes exceeding joins).

Among visits with a recorded source category (first page of a visit, including direct), 176 of 353 visits in the last 7 days came from ChatGPT (50%), 134 were direct (38%), and 21 came from Google (6%). Over 30 days (1,236 visits), ChatGPT sent 515 (42%), direct was 539 (44%), and Google sent 66 (5%). Neither site has been promoted externally yet, and a quick web search shows no third-party links pointing to either domain.

Rolovia has only been live for three days, so almost all of its 25 visits so far are my own checks, plus the first two organic clicks from Google.

cloudflaredurable-objectsboard-gamesai-agents