DEVOURED
Under the hood, off the hot path: How D1 scales to millions of databases
Cloudflare scaled its D1 serverless SQLite platform to support millions of databases by decoupling the control plane from the hot-path query execution.
What: Cloudflare engineers David Laban and Lambros Petrou redesigned the D1 control plane to use idempotent, recoverable workflows and eventually consistent queues. D1 now separates query processing—which stays at the edge using D1 Durable Objects—from control tasks like database creation, which utilize Hyperdrive for efficient Postgres metadata access.
Why it matters: This architecture demonstrates a transition toward 'database-per-user' models in serverless environments, where centralized management must be decoupled to prevent bottlenecks while allowing for massive scaling of isolated database instances.
Takeaway: If building platforms that require millions of managed databases, isolate your control plane from data path traffic and use Workers KV for globally distributed routing metadata.
Deep dive
- D1 uses SQLite backed by Durable Objects to enable millions of isolated databases per account.
- The control plane uses Postgres in central regions for transactional metadata, while query traffic remains at the edge.
- Creation workflows are idempotent and use periodic heartbeats to resolve state between the Durable Object and Postgres.
- To prevent bottlenecks, query routing metadata is cached in Workers KV to avoid central database lookups during user requests.
- Storage limits are enforced using incremental view maintenance in Postgres to avoid expensive account-level aggregation queries.
- ClickHouse is used for analytical workloads to avoid overloading Postgres for usage event tracking.
- The architecture prioritizes eventual consistency for administrative tasks to keep the query data path highly performant.
Decoder
- Durable Object (DO): A stateful serverless primitive on Cloudflare Workers that provides persistent storage and consistent execution within a specific location.
- Hyperdrive: A connection pooling service that routes database queries from the edge to central data centers.
- Workers KV: A globally distributed, low-latency key-value store integrated into the Cloudflare platform.
- Service Binding: An interface allowing one Cloudflare Worker to communicate directly with another, bypassing public HTTP routing.
Original article
Full article content is not available for inline reading.
Explore all 62 articles in today's digest
Fresh dev news, AI-digested daily. Never miss a trend at devoured.fyi