The first version couldn't be given away
Dungeon Garden runs a game of D&D across a few screens: a TV view everyone watches (a TV in the room, or a screen shared on a Discord call), each player's phone, and the DM's console. Change something on one and the others update.

The first version online was a Next.js app on Vercel with Upstash Redis, which is the stack I knew. It worked, and it was built for one game: a single DM key for the whole site. A couple of hours after it was merged, I asked:
how could I make this not use redis and rather use the DMs machine as the node to offload 100% of the server cost to the client? Then I could just give this away to people / the public
The shape of a bill
I can't show a before-and-after bill. The first version was online for about ten hours with no real groups on it. What I can show is how each version turns one click into work someone charges for. Take seven screens (the DM, the TV and five phones) and a DM who pays the party:
Before: Next.js on Vercel, Redis
- The click runs one server function, which reads the game from Redis, saves it and announces a new version.
- Seven screens hear it, and each runs another function to fetch its own view, reading Redis again.
- Meanwhile, every open screen holds a server function open (restarted every 270 seconds) for as long as it's on. A four-hour session is a lot of function time.
After: one room per group
- The click is one request, passed to that group's room.
- The room saves to its own small SQLite database.
- It sends seven messages over the screens' open WebSockets. Cloudflare doesn't charge for those.
- Between clicks the room can sleep, and the screens' keep-alive pings don't wake it.
The first shape costs more the longer screens stay open. The second costs more only when someone does something. A game runs for hours and changes something every few seconds at most, so only the second can stay free.
Before: one game on Redis
What each part did
- Writes were a POST. The server read the game, ran the rules, then saved with a Lua script that refused if the version had moved on.
- Updates were a version number on a server-sent events stream. The stream carried no game data, so it needed no sign-in. Each screen then asked for its own view.
- The DM was whoever held the one
DM_KEY. Fine for my table, wrong for anyone else's.
After: a room per campaign
What each part does
- The Worker is the front door. It never holds game state. It finds the room by name and hands the request over.
- The room is one Durable Object instance. Cloudflare runs at most one instance for a given name, so every screen at a table talks to the same copy of the game.
- Updates are the whole view each screen is allowed to see, sent over its WebSocket after every save. Not a diff.
Three options, one morning
| Option | The appeal | The catch |
|---|---|---|
| Run it on the DM's laptop, on the local network | No server bill at all. | Only works for phones on the same Wi-Fi. A remote player gets nothing. |
| Peer-to-peer (WebRTC) from the DM's browser | Also close to no server. | The DM's tab becomes the server: close it and the game goes dark. Still needs relay servers for some phones. Rated the hardest. |
| A tiny server per group (Cloudflare Durable Objects) | Works from anywhere, and an idle group costs next to nothing. | Not literally free, and it meant leaving Next.js. If it worked, I didn't mind what it ran on. Chosen, and merged that morning. |
Cost wasn't the only reason to move. My Vercel account is paid for through madtown.today, and I wanted Dungeon Garden's hosting to stand on its own.
One room per group
A Durable Object is a small server Cloudflare keeps for a name you give it, with its own storage. Cloudflare runs at most one copy of a given one at a time, so every screen in a game talks to the same copy. Dungeon Garden calls each one a room, and the campaign code is its name. There's no central database to look up first, and no shared table where one group's data sits next to another's.
function room(env: Env, game: string) {
return env.ROOMS.get(env.ROOMS.idFromName(game));
}
The ROOMS namespace
Why the names matter
- Same code, same room.
idFromNamealways gives the same id for the same name, so no lookup table sits in front of the rooms. - Nothing shared. A room only ever reads its own storage. One table's save can't block or see another's.
- Practice rooms are named
practice:<code>. Codes are letters, digits and dashes, so no one can type their way into one. - Guesses cost nothing. A room only creates its tables on the first real save, so a wrong code leaves no rows behind.
Three details keep rooms cheap to leave lying around. A room only creates its storage on the first real save, so a mistyped or guessed code leaves nothing behind. A campaign nobody has touched for 180 days deletes itself and its images. And a DM's practice copy lives in a separate room, so rehearsing never touches the real game.
Try it: codes and rooms
Simulation in your browserStart a campaign, then try opening its code again, or a code nobody made.
What this simplifies
- The ids here are SHA-256 of the code, cut short. Cloudflare makes the real ones; the demo only copies the promise that a name always maps to the same id.
- Real rooms live in Cloudflare, not in this tab, and starting a campaign also makes a DM key. Nothing here is sent anywhere.
- In the real app a code someone picks must have at least 8 letters or digits. Made-up codes are 7 characters from a 31-character alphabet, with look-alikes like 0, o, 1 and l left out.
Cheap, and still in step
After every change, the room sends each screen the whole picture it's allowed to see: the DM sees everything, the TV sees what's on the TV, and a player sees their own gold and not their friend's secrets. Sending the whole picture instead of a list of changes costs a few more bytes, but a phone that slept through three changes only needs the next one. Since outgoing messages are free, the extra bytes don't cost anything.
Try it: one change, three screens
Simulation in your browserDM consolev41
- Wren12 gp
- Tolly7 gp
- DM noteThe ferryman is lying.
Table TVv41
- Party purse19 gp
- DM notenot sent
Wren’s phonev41
- My gold12 gp
- Tap a square to move
- Room is at version 41. Three screens connected.
What this simplifies
- It runs entirely in this page. There is no Worker, no Durable Object and no network, so the delays are made up.
- The real room runs more than two hundred kinds of command through one rules function, and a view holds far more than gold and two tokens.
- In the real app the phone keeps its own move on screen while it waits, and the room only lets a player move their own token, on the map that is on the TV, unless the DM has locked it.
- The version check and retry loop came across unchanged from the Redis version, where several functions really could write at once. The demo forces a clash so you can see it.
Phones lock and drop Wi-Fi, so each screen checks in every 25 seconds and replaces a connection it hasn't heard from in 75. Those check-ins are answered without waking the room:
// Keep-alive pings from the browser are answered without waking the room.
ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair("ping", "pong"));
How a save and an update look in the code
async commit(game: string, expected: number, state: GameState, ledger: LedgerEntry[]) {
const d = this.load();
if (d.version !== expected) return null; // someone saved first: the caller retries
// …
this.ctx.storage.transactionSync(() => {
this.save(game, next);
for (const e of entries) this.sql.exec("INSERT INTO ledger (entry) VALUES (?)", JSON.stringify(e));
});
// …
}
/** The game changed: push every open screen its own view. Outgoing messages are free. */
async publish(_game: string, _version: number) {
for (const ws of this.ctx.getWebSockets()) await this.push(ws);
}
madtown.today: knowing where the bill comes from
madtown.today still runs on Next.js, Vercel and Upstash Redis, and that's fine for it: it's a homepage people check in on, not a game they keep open for hours. What matters is knowing which feature costs what. Its README spells it out:
Presence is almost all of it: 4 commands per heartbeat, so about 8 commands per visitor per minute while their tab is visible … Finishing a game costs about 10.
The “who's here” card, where you can see and wave at other people on the page, is the expensive part, not the puzzles. The README works through two cases: a launch spike of 200 people for three hours comes to about 290,000 commands, and a steady 20 people around the clock for a month to about 6.9 million. Its advice if that gets tight is one setting: send the heartbeat every 60 seconds instead of 30, which halves the cost and only makes the online count update more slowly.
That README note turned out to be out of date. When I read the real bill, the heartbeat was a small part of it. The rest, and the plan to fix it, is in What madtown.today actually costs.
The rest leans on free things used gently. The weather comes from Open-Meteo, free for non-commercial use, fetched at most once every 10 minutes for everyone, and your game history stays in your own browser, which costs nothing.
Put together, here is what madtown.today costs to run. It publishes its own counts, so the numbers beside it are real:
What madtown.today costs to run
Live counts| Each month | For | Cost |
|---|---|---|
| Upstash Redis, 250 MB | counters, presence, the guestbook | $15 |
| Total | $15 | |
The 250 MB Upstash Redis database that holds everything.
- Visitors a day
- 375
- Games played
- 23,142
- Since launch
- 8,342
- Per visitor-day
- 0.13¢
The last 29 full days, from madtown.today's own counts, refreshed twice a day. A visitor is one browser on one day, so someone who comes back every day counts every day. Games played adds up finished Four Lakes and Word games, solved Chair Stacks and Madison Asks votes. Per visitor-day is the monthly bill over a month of visitors at this pace.
The prices, as published
Checked on 21 November 2026. They'll change.
| Service | Free plan | Notes |
|---|---|---|
| Cloudflare Workers | 100,000 requests a day | Paid plan: $5 a month, 10 million requests included. |
| Durable Objects (SQLite) | 100,000 requests a day; 5 million rows read and 100,000 rows written a day; 5 GB stored | Outgoing WebSocket messages aren't billed; incoming ones count as one request per 20. A sleeping object isn't billed for time. |
| Upstash Redis | 500,000 commands a month | Changed on 12 March 2025. Before that, the free plan was 10,000 commands a day. |
I'm not putting a number on how many groups fit in Dungeon Garden's free plan. That depends on how people play, and I'd rather measure it than guess. The DM console has a Hosting costs box that counts what each campaign actually uses, so that number will come from real games.
What I'd tell someone trying this
- Work out what an idle user costs before you work out what a busy one costs. For giveaway software, idle is most of the time.
- Prefer designs where the bill follows actions, not open tabs.
- Write down which feature costs what, like madtown.today's README does, so the cheap fix is obvious when you need it.
- Don't quote capacity you haven't measured. Build the meter first.
How it was built
I didn't type most of Dungeon Garden's code. Every code commit in its repository was written by Claude Code, working from my direction. My part was deciding what it should be and what it shouldn't: the product, every feature, the calls in this piece, having my own site attacked to find holes, and merging each change. The Redis version went up on the evening of 12 November 2026 (US Central), the room-per-group version the next morning.