D1 Database
What is it?
D1 is Cloudflare's serverless SQL database, built on SQLite. It lets developers create and query relational databases without managing any infrastructure. Databases are automatically replicated globally for fast reads, and they integrate natively with Workers — your application code and database are on the same network.
What problem does it solve?
Every serious application needs a database, but traditional databases have significant friction:
- Provisioning and scaling: Setting up PostgreSQL or MySQL in the cloud requires choosing regions, configuring instances, managing connections, and scaling capacity.
- Latency: Centralized databases in one region mean high latency for users far from that region.
- Cost: Managed database services (like AWS RDS or Google Cloud SQL) can be expensive, even when idle.
- Complexity: Developers building on serverless platforms often resort to awkward workarounds (like using key-value stores as databases) because traditional databases don't fit the serverless model.
D1 solves this by being a serverless, globally distributed SQL database that developers can create with a single command.
How does it work?
- A developer creates a D1 database using the Wrangler CLI:
wrangler d1 create my-database - They define tables and queries using standard SQL.
- The database is bound to a Worker, meaning the Worker can query it directly without network connections or connection pools.
- Writes go to a primary location, while reads are served from replicas distributed globally for low-latency access.
- The database can also be queried via the Cloudflare API or dashboard.
Key features:
- Standard SQL interface (SQLite dialect)
- Time Travel: Query your database at any point in the last 30 days — effectively free backups.
- Import/Export: Import existing SQLite databases or CSV files.
- Batch operations: Execute multiple queries in a single round trip.
Why it matters strategically
D1 is critical for making Cloudflare a complete application platform. Without a database, Workers could only build stateless applications or depend on third-party databases. D1 means developers can build full-stack applications entirely on Cloudflare — compute (Workers), storage (R2), database (D1), and hosting (Pages). This is essential for competing with AWS, Vercel, and other cloud platforms.