Cloudflare D1 is a serverless SQLite database that runs at the edge. Your data lives close to your users — globally distributed with automatic replication.
Why D1 Changes Edge Computing
A developer had a Cloudflare Worker that needed a database. Options were external DB calls adding 100ms+ latency. D1 runs alongside Workers at the edge — database queries in under 1ms.
Key Features:
- SQLite at the Edge — Familiar SQL, global distribution
- Zero Cold Starts — Always warm, always fast
- Automatic Replication — Read replicas near users automatically
- Time Travel — Restore to any point in time (30 days)
- Free Tier — 5GB storage, 5M reads/day, 100K writes/day
Quick Start
npx wrangler d1 create my-db
// Cloudflare Worker
export default {
async fetch(request, env) {
const { results } = await env.DB.prepare(
"SELECT * FROM users WHERE id = ?"
).bind(1).all()
return Response.json(results)
}
}
Migrations
npx wrangler d1 migrations create my-db init
-- migrations/0001_init.sql
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE
);
npx wrangler d1 migrations apply my-db
Why Choose D1
- Edge-native — database at every Cloudflare location
- SQLite — no new query language to learn
- Generous free tier — 5M reads/day for free
Check out D1 docs to get started.
Need edge solutions? Check out my Apify actors or email spinov001@gmail.com for custom solutions.
Top comments (0)