A Real Database, No Server to Manage
The first four projects in this series ran entirely in the browser. This one breaks that streak on purpose - a shared guestbook backed by Cloudflare D1, a real SQL database that runs at the edge with no server to provision, patch, or pay for while it is idle.
Projects 01 through 04 in this series had a rule: everything happens in the browser. Text to speech, speech to text, notes in IndexedDB, files edited straight to disk. No backend, no database, no server bill.
Project 05 breaks that rule on purpose.
Some things genuinely need a server - specifically, anything that has to be true for more than one person at once. IndexedDB notes only exist on your machine, in your browser. If you want the same data to show up for a friend on their phone, something has to sit between you and them. That something is usually a database.
The old way to get one meant provisioning a Postgres instance, picking a region, managing connections, and paying for it whether or not anyone visits your app. Cloudflare D1 skips all of that.
What D1 actually is
D1 is SQLite, run by Cloudflare, attached directly to a Worker or Pages Function as a binding. There is no connection string, no pool to manage, no idle instance burning money at 3am. You write SQL, bind the database in a config file, and query it from a function that only runs when a request comes in.
export async function onRequestGet({ env }) {
const { results } = await env.DB.prepare(
'SELECT id, author, content, created_at FROM notes ORDER BY id DESC LIMIT 100'
).all()
return Response.json(results)
}
That env.DB is the entire integration. No ORM required, no driver to install, no environment variable to leak.
What I built
A serverless guestbook. Anyone who opens the page can leave a short note with an optional name. Every note is stored in D1 and shown to every visitor - reload the page, open it on another device, send the link to a friend, everyone sees the same list.
That is the whole point of the demo: it is the opposite of project 03. IndexedDB notes were private and local. D1 notes are shared and centralized. Same shape of app, opposite storage model - a deliberate side-by-side of "your browser remembers" versus "the internet remembers."
Features:
- Shared, persistent notes - stored in a real SQL table, not local storage
- Optimistic delete - the UI removes a note instantly, then confirms with the server
- Input validation on the server - empty notes get rejected with a 400, not silently dropped
- Local dev with zero cloud setup -
wrangleremulates D1 on your machine with SQLite, no Cloudflare account needed to develop - Two commands to run it -
npm install && npm run dev, same as every other project in this series, D1 included
Running it locally without a Cloudflare account
This is the part that surprised me. wrangler pages dev proxies your Vite dev server and wraps it with a local Worker runtime (Miniflare) that emulates D1 with an actual SQLite file on disk, under .wrangler/state. No network calls to Cloudflare happen in development.
wrangler d1 execute DB --local --file=./schema.sql # creates the table, locally
wrangler pages dev -- vite # runs Vite + the Functions + D1, together
You get hot reload on the frontend and a real database, both running on your laptop, before you have deployed anything or created a Cloudflare account.
Deploying it for real
Everything above runs with zero Cloudflare account. Deploying is the only point where you need one - Cloudflare's free tier covers this project comfortably (D1's free tier alone is 5GB and 5 million rows read per day).
wrangler login # one-time browser auth
wrangler d1 create serverless-db-demo # provisions the real database
# prints a database_id - paste it into wrangler.toml, replacing "local-dev"
wrangler d1 execute DB --remote --file=./schema.sql # creates the table on the real DB
npm run build # outputs to dist/
wrangler pages deploy dist --project-name serverless-db-demo
One manual step the CLI does not do for you: open the new Pages project in the Cloudflare dashboard, go to Settings → Functions → D1 database bindings, and add a binding named DB pointing at serverless-db-demo (both Production and Preview). That is what lets the deployed Functions in functions/api/notes/ actually see env.DB - the code itself is identical to what ran locally.
Why this matters
The pitch for serverless databases is usually about scale - "handles millions of requests." The more useful pitch for a solo developer is the opposite end: it costs nothing and requires nothing while your app has ten users, and it still works unmodified if it ever has ten million. There is no server to remember to shut down, no bill for a database sitting idle overnight.
This is project 05 in the build-it-small series. The first four proved browsers can do more than you think. This one proves the backend for a real, shared, multi-user feature can be smaller than you think too.
Try it: serverless-db.ismyapp.com (or wherever you deploy it)
Source code: github.com/paolinellih/build-it-small
Previous in the series:
- Project 01 - Text to Speech in the Browser - No Server, No Cost, No Excuses
- Project 02 - Speech to Text in the Browser - No Backend, No Bill
- Project 03 - Your Browser Has a Database. Most Developers Never Use It.
- Project 04 - Your Browser Can Edit Real Files Now