SERVERLESS DATABASE

Cloudflare D1

SQLite-based serverless database that runs at the edge. Read replicas across 330+ locations, zero cold starts, built-in time travel — relational data without infrastructure.

Talk to an engineer →
THE CHALLENGE

Centralized databases bottleneck edge applications.

Edge compute gains are lost when every request round-trips to a single-region database

Managed database services (RDS, Cloud SQL) require capacity planning, patching and failover configuration

Serverless databases (Aurora Serverless, PlanetScale) still run in fixed regions with cold start penalties

Database connection pooling and management adds complexity to every serverless function

OUR APPROACH

SQL at the edge, managed by Cloudflare.

01

D1 schema design

We design normalized schemas optimized for D1's SQLite engine. Indexing strategies, query patterns and data modeling for edge-first applications.

02

Migration from existing databases

Migrate from PostgreSQL, MySQL, SQLite or NoSQL to D1. Schema conversion, data migration scripts and application query adaptation included.

03

Read replica architecture

D1 automatically replicates reads to edge locations near your users. We architect your application to maximize read-replica hits for sub-millisecond query times.

04

Workers binding integration

Direct D1 access from Workers without connection strings or pooling. We implement type-safe query builders, migrations and seed scripts for your development workflow.

USE CASES

D1 in production.

Edge-native APIs

REST and GraphQL APIs with sub-10ms database queries. User profiles, product catalogs, configuration stores — all at the edge.

Auth & session storage

User authentication, session tokens and permission checks without round-tripping to a central database. GDPR data residency with location hints.

Analytics & logging

Write event data at the edge, query with standard SQL. Real-time dashboards without dedicated analytics infrastructure.

Multi-tenant SaaS

Database-per-tenant isolation using multiple D1 databases. Each tenant gets their own SQLite instance with independent scaling.

ARCHITECTURE

D1 database architecture.

D1 uses a single-writer primary with automatic read replicas distributed across Cloudflare's edge. Write queries go to the primary; read queries are served by the nearest replica — delivering sub-millisecond read latency globally.

COMPARISON

D1 vs. serverless databases.

How Cloudflare D1 compares to PlanetScale, Neon, Turso and AWS Aurora Serverless for edge-native applications.

FeatureCloudflare D1PlanetScaleNeon Postgres
EngineSQLiteMySQL (Vitess)PostgreSQL
Edge replicasAutomatic (global)No (single region)Read replicas (manual)
Cold start0ms (Worker binding)~100ms~500ms (suspend)
Free tier5M reads/day, 100K writes1B reads/month0.5GB storage
Max database size10GB5GB (Hobby)0.5GB (free)
Time travel30 days built-inNoNo (branching instead)
BranchingNot yetYesYes
Pricing$0.001/M reads$0 → usage-based$0 → usage-based
IMPLEMENTATION

Our D1 implementation process.

From schema design to production — how we build edge-native database applications on D1.

01

Data Modeling

Design normalized schemas optimized for SQLite. Define indexes, query patterns and migration strategy. If migrating from Postgres/MySQL, map schema differences.

3–5 days
02

Application Development

Implement type-safe D1 queries with Workers binding. Build migration scripts, seed data. Set up local development with Wrangler D1 emulation.

1–3 weeks
03

Performance Testing

Benchmark read/write patterns. Optimize queries for read-replica architecture. Test time travel recovery. Load test with realistic traffic.

3–5 days
04

Production Deployment

Deploy D1 database with production configuration. Set up monitoring, alerting and backup verification. Document schema and migration procedures.

2–3 days
Cloudflare products: D1WorkersHyperdriveKVDurable ObjectsAnalytics Engine
FAQ

Frequently asked questions.

Is D1 production-ready?

Yes. D1 is generally available (GA) as of 2024. It supports databases up to 10GB, handles millions of reads per second across edge replicas, and includes time travel (point-in-time recovery) for the last 30 days.

Can D1 replace PostgreSQL or MySQL?

For many workloads, yes. D1 uses SQLite — which supports most standard SQL. Complex features like stored procedures, triggers and advanced joins work. For workloads requiring PostgreSQL-specific features (JSONB operators, extensions), we use Hyperdrive to connect Workers to your existing database instead.

How does D1 handle writes across regions?

D1 uses a single-writer architecture — writes go to the primary location, reads are served from edge replicas. Write latency depends on distance to the primary. For write-heavy workloads, we architect with Durable Objects for regional write coordination.

Ready to get started with Cloudflare D1?

Book a free assessment call with our Cloudflare engineering team.

Schedule assessment → All Cloudflare services