What is Cloudflare D1 and how does it differ from traditional databases?
D1 is a serverless SQL database built on SQLite that runs on Cloudflare's edge network. Unlike traditional databases that run on a single server, D1 automatically replicates reads globally for low latency. It requires no server provisioning, scales to zero when inactive, and charges only for actual query and storage usage.
Is D1 compatible with standard SQL?
Yes. D1 uses SQLite's SQL dialect, which supports standard SQL operations including SELECT, INSERT, UPDATE, DELETE, JOINs, subqueries, and indexes. However, it does not support every feature found in PostgreSQL or MySQL, such as stored procedures or certain advanced data types.
What is Time Travel and how does it work?
Time Travel is D1's built-in backup and recovery feature. It automatically maintains a recovery history, allowing you to restore any database to any point within the last 30 days. This eliminates the need for manual backup scripts or third-party backup services.
How much does Cloudflare D1 cost?
D1 has a free tier with 5 million rows read/day, 100K rows written/day, and 5 GB storage. The paid tier includes 25 billion reads/mo and 50 million writes/mo. Beyond that, additional reads cost $0.001/million rows, writes cost $1.00/million rows, and storage costs $0.75/GB-month. There are no egress fees.
Can I use D1 outside of Cloudflare Workers?
D1 databases can be queried via HTTP API from external applications, though the primary integration is with Cloudflare Workers and Pages. Dashboard and CLI queries also work but count toward billable usage. For the best performance and developer experience, D1 is designed to be used within the Cloudflare ecosystem.
Why is D1 limited to 10 GB per database?
The 10 GB limit per database reflects D1's design philosophy of distributed, multi-database architectures. Instead of one large database, D1 encourages patterns like per-user or per-tenant databases. There is no extra cost for creating multiple databases, so this constraint rarely limits practical applications.