Thoughts on Cloudflare D1: A new era

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:

(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?

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:

Okay that’s cool and all but what did I even build?

Often in my side projects, I find myself needing to move files between my computer and various servers. A really easy way to do that is to upload it to the service https://transfer.sh - this service allows uploading files from the browser or command-line. Unfortunately, that site can be pretty slow. But because it’s open-source, I was able to host my own instance of it on https://railway.app (a platform for running containers in the cloud.)

But where does D1 come in?

When I upload a file to my transfer service, it’s only kept around for a day to save space. But it’d be cool if I could see what all I uploaded to it over time! However, would it be cool enough to provision a Postgres database somewhere for it? Absolutely not. Instead, I went into my Worker that sits in front of the service and added 55 lines of code that record each upload to a D1 database: https://github.com/jahands/transfer.sh/blob/1cd8810fed4c0248ae0a6730d0e4f51372da0cab/cf-worker/src/api.ts#L45-L99

Seems nice and all, but what do I do with the data?

I query it for fun using d1-console (basically psql but for D1, made by one of our Cloudflare Discord Community Champions, Isaac McFadyen). No business case, it’s not useful to anyone else, and it’s definitely not worth maintaining a database somewhere for. But it’s cool to me that I can see a history of files that I uploaded to the service, and it was fun to build.

That’s ridiculous, why don’t I build something useful instead?

I’ve been told this many times. But over the years, I’ve learned that my “pointless” projects often help later on. Even if it’s just practicing my ability to figure things out, or staying excited about tech and what’s possible with programming: building things is never a waste of time if I’m having fun.

In conclusion

D1 is exciting because for the first time in 14 years of programming, I’m building databases into my everyday projects because it’s finally easy. It’s like a whole new world has opened up for me, making possibilities feel endless. Who knows, maybe I’ll build something that outgrows D1 and needs to move to something heavier like Postgres. But I was never going to get to that point when “it’ll be good enough without a database, they’re too much effort.” The time to build with databases is here, and it starts with D1!

Ps. If you’re curious how I built this, check out the source code on GitHub