I built a project this past weekend using Cloudflare D1 and wanted to share my thoughts on why it’s a game-changer. But first, I want to share some context about how I got here, and what D1 means to me.
There have been a few pivotal moments in my life as a developer:
- Visual Studio allowed me to make programs in Visual Basic when I was 13, before I even knew what a variable was.
- Digital Ocean allowed me to run services/programs 24/7 on an amazing Internet connection in the cloud, opening up a lot of new possibilities for the kinds of things I could build.
- Minecraft taught me SQL when I worked on a server plugin for some friends when I was ~15-16.
- PowerShell allowed me to automate everything on Windows/Linux after it added Linux support in 2016.
- Cloudflare Workers made “Serverless” make sense to me for the first time in 2018, changing the way I developed and thought about web applications forever.
- The Elgato Stream Deck gave me a whole new way to control computers in 2021, helping me automate complex problems without needing to do front-end development to build a user interface.
- Cloudflare Pages made deploying static (and later, dynamic) websites so easy that even I could do it in 2021.
(Disclaimer: I work for Cloudflare on the Pages team, opinions are my own.)
There has always been something missing: databases!
Other than the short stint in Minecraft, where I was helping someone else with their database queries, I’ve never really used databases for personal projects. The closest thing I ever use are KV stores because they’re easy/cheap. But proper databases have always been too hard for me to want to use for small projects (which is basically all my projects before joining Pages.)
But why are databases hard?
- They require work to maintain. Instead of working on my project, I now have to manage a server, backups, and security. This adds mental overhead that is hard to justify for small projects, especially if they’re just for fun.
- Cost: Databases are expensive, whether I run them myself, or get a hosted solution. Even free-tier DBs from great platforms like Supabase feel too expensive for something that may get a few queries a month (or maybe never again for some of my projects!) It may not be expensive for me, but in my mind free-tier is going to eventually go away/get shut down if the platform needs to run a whole container running Postgres for my 0-3 queries a month.
Why D1 is a game-changer:
On the surface, D1 is just another database right? Not quite, there are some big advantages over other solutions:
- It’s easy! Run a wrangler command to create a DB, copy-paste the binding to
wrangler.toml, and it’s ready to use. No servers, no passwords to manage, no complicated setup.
- It’s small: Since D1 is backed by SQLite, Cloudflare doesn’t have to run expensive containers for my tiny database. Because it’s cheap for Cloudflare to host low-volume D1 databases, I feel confident that my barely-used databases won’t disappear or get shut down.
- It Just Works™: While it’s not the fastest (yet), it works fine without having to think about it. For me, removing all this mental overhead so that I don’t have to think about the database means I can actually build the thing I wanted to in the first place.