← Small software

Small software · 3 of 4

Cheap enough to give away

Free software is only free if someone can afford to keep it running. The question that decides it isn’t how many people use it, but what an idle user and an idle group cost. Here is how Dungeon Garden was rebuilt around that question, and where madtown.today’s bill comes from.

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 Dungeon Garden TV view: a town map of Marrowmere with numbered places, the party's tokens and a party purse in the corner
The TV view, showing the built-in example campaign. Screenshots come from a throwaway test campaign.

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
On record My message, 13 November 2026, 07:22 UTC. Spelling as typed.

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

  1. The click runs one server function, which reads the game from Redis, saves it and announces a new version.
  2. Seven screens hear it, and each runs another function to fetch its own view, reading Redis again.
  3. 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

  1. The click is one request, passed to that group's room.
  2. The room saves to its own small SQLite database.
  3. It sends seven messages over the screens' open WebSockets. Cloudflare doesn't charge for those.
  4. 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

The first deployed versionEach screen talks to Next.js functions on Vercel. A change is a POST that runs a Lua script on Upstash Redis and publishes the new version number. Every screen holds a server-sent events stream that only carries version numbers, then fetches its own view. Images go to Vercel Blob. One DM key, set as an environment variable, covers the whole site.DM laptopTable TVPhonesPOST /api/commandSSE: "version 42"then GET /api/viewfrom every screenNext.js 16 functions on Vercelone long-lived stream function per open screen,closed after 270 s and reopened (limit: 300 s)DM_KEY: one environment variableMGET · EVAL · PUBLISHUpstash Rediscf:<game>:statecf:<game>:vercf:<game>:ledger+ a pub/sub channel per gameVercel Blobimages
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

The public versionScreens send changes as HTTP posts to a Cloudflare Worker and hold one WebSocket each. The Worker serves the static app, applies rate limits, and forwards each request to the campaign's Durable Object, found by name from the campaign code. The room saves to its own SQLite storage and pushes every connected screen its own view. Images go to an R2 bucket.DM laptopTable TVPhonesPOST /api/commandWebSocket: your viewthe whole filteredview, pushedWorker "candlefair"static app · rate limits · uploads to R2ROOMS.idFromName(code)GameRoom (Durable Object)one per campaign codeSQLite: doc · ledgerdm_key_hashits own socketsdeleted after 180 idle daysR2images
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

OptionThe appealThe catch
Run it on the DM's laptop, on the local networkNo 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 browserAlso 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));
}
worker/index.tsat Dungeon Garden f8de4ba

The ROOMS namespace

One namespace, many roomsThe Worker turns a campaign code into a Durable Object id with idFromName. Each code gets its own room with its own storage and sockets. A practice copy lives under the name practice: plus the code, which no typed code can produce. A guessed code that was never created leaves nothing stored. A separate Registry object lists campaigns for the site admin page.Worker?game=<code>idFromName(code)ROOMS · class GameRoom · SQLitek7m2qpxmade-up code, 7 lettersdoc · ledger · socketsmarrowmere-crewa code the DM chosedoc · ledger · socketspractice:k7m2qpxprivate rehearsal copydoc · ledger · socketszzzzzzza guess: nothing storedRegistry ("admin:registry")a separate object that lists campaigns for my admin page
Why the names matter
  • Same code, same room. idFromName always 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 browser

Start 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 browser

DM 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
  1. 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"));
worker/room.tsat Dungeon Garden f8de4ba
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);
}
worker/room.tsat Dungeon Garden f8de4batrimmed

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.
On record madtown.today README, “Redis cost”

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 monthForCost
Upstash Redis, 250 MBcounters, 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.

ServiceFree planNotes
Cloudflare Workers100,000 requests a dayPaid 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 storedOutgoing WebSocket messages aren't billed; incoming ones count as one request per 20. A sleeping object isn't billed for time.
Upstash Redis500,000 commands a monthChanged 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

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.