Cloudflare D1

Cloudflare D1

SQLite at the edge on Cloudflare's global network

Features

  • SQLite-compatible database on Cloudflare's edge
  • Automatic read replication across edge locations
  • Time Travel for point-in-time recovery
  • Native integration with Cloudflare Workers

Pros

  • Ultra-low latency with edge-located data
  • SQLite compatibility — familiar tools and syntax
  • Generous free tier included with Workers

Cons

  • Locked into Cloudflare Workers ecosystem
  • Write operations go to primary — higher latency
  • Size and query limitations compared to full databases

Overview

Cloudflare D1 is a serverless SQLite database that runs on Cloudflare’s global edge network. It provides a familiar SQLite interface with automatic read replication, making it ideal for applications built on Cloudflare Workers that need low-latency data access.

D1 stores data in SQLite format but adds cloud features like automatic backups, point-in-time recovery (Time Travel), and read replication across Cloudflare’s network. It integrates natively with Workers, allowing direct database access from edge functions without external network calls.

When to Use

D1 is the natural choice when building applications on Cloudflare Workers that need persistent storage. It’s ideal for read-heavy workloads at the edge, content-driven applications, and projects where the Cloudflare ecosystem is already your deployment target.

Getting Started

# Using Wrangler CLI
npx wrangler d1 create my-database
npx wrangler d1 execute my-database --command "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)"
export default {
  async fetch(request, env) {
    const { results } = await env.DB.prepare(
      "SELECT * FROM users"
    ).all();
    return Response.json(results);
  },
};