← Field notes

R2 + D1: the serverless stack that replaces your VPS

cloudflarer2d1serverless

For years the default answer to “I need a database and somewhere to put images” was a VPS. You rent a box, install the stack, and then spend forever patching it. Cloudflare has quietly made that answer obsolete for a large class of sites.

R2: media without the egress tax

Cloudflare R2 is object storage with zero egress fees. That’s the part that matters. Amazon S3 charges you to get your own files back out; R2 doesn’t. For an image-heavy site, that single difference can be worth hundreds of dollars a month.

The workflow I use on every migration:

  1. Convert every image to WebP or AVIF before upload — modern formats are 30–50% smaller at the same quality.
  2. Upload to R2 and reference the public R2 URL directly.
  3. Let Cloudflare’s CDN cache the hot files automatically.

No image optimization plugin, no CDN subscription, no origin server sitting between the visitor and the file.

D1: SQL without a server

D1 is Cloudflare’s serverless SQLite. It lives at the edge, it’s queried from Workers or Pages Functions, and it costs almost nothing until you have real volume.

The honest limitation: it’s SQLite, so it’s not a drop-in replacement for a heavily relational PostgreSQL workload. But for forms, comments, product catalogs, or a simple CMS backend, it’s more than enough — and you never think about it again.

When you still need a VPS

If you’re running a real-time service, long-running processes, or something with heavy write contention, keep the server. The serverless stack is for the 90% of sites that are mostly read, occasionally write, and don’t need a daemon running all night.