Choose a data or storage product
Cloudflare Workers support a range of storage and database options for persisting different types of data across different use-cases, from key-value stores (like Workers KV) through to SQL databases (such as D1). This guide describes the use-cases suited to each storage option, as well as their performance and consistency properties.
Available storage and persistency products include:
- Workers KV for key-value storage.
- R2 for object storage, including use-cases where S3 compatible storage is required.
- Durable Objects for transactional, globally coordinated storage.
- D1 as a relational, SQL-based database.
- Queues for job queueing, batching and inter-Service (Worker to Worker) communication.
- Hyperdrive for connecting to and speeding up access to existing hosted and on-premises databases.
- Analytics Engine for storing and querying (using SQL) time-series data and product metrics at scale.
- Vectorize for vector search and storing embeddings from Workers AI.
Applications built on the Workers platform may combine one or more storage components as they grow, scale or as requirements demand.
Use-case | Product | Ideal for |
---|---|---|
Key-value storage | Workers KV | Configuration data, service routing metadata, personalization (A/B testing) |
Object storage | R2 | User-facing web assets, images, machine learning and training datasets, analytics datasets, log and event data. |
SQL database | D1 | Relational data, including user profiles, product listings and orders, and/or customer data. |
Time-series metrics | Analytics Engine | Write and query high-cardinality time-series data, usage metrics, and service-level telemetry using Workers and/or SQL. |
Global co-ordination | Durable Objects | Building collaborative applications; global co-ordination across clients; strongly consistent, transactional storage. |
Vector search (database) | Vectorize | Storing embeddings from AI models for semantic search and classification tasks. |
Task processing & batching | Queues | Background job processing (emails, notifications, APIs) and log processing/batching. |
Connect to an existing database | Hyperdrive | Connecting to an existing database in a cloud or on-premise. |
The following table highlights the performance and consistency characteristics of the primary storage offerings available to Cloudflare Workers:
Feature | Workers KV | R2 | Durable Objects | D1 |
---|---|---|---|---|
Maximum storage per account | Unlimited1 | Unlimited2 | 50 GiB | 250GiB 3 |
Storage grouping name | Namespace | Bucket | Durable Object | Database |
Maximum size per value | 25 MiB | 5 TiB per object | 128 KiB per value | 10 GiB per database 4 |
Consistency model | Eventual: updates take up to 60s to be reflected | Strong (read-after-write)5 | Serializable (with transactions) | Serializable (no replicas) / Causal (with replicas) |
Supported APIs | Workers, HTTP/REST API | Workers, S3 compatible | Workers | Workers, HTTP/REST API |
1 Free accounts are limited to 1 GiB of KV storage.
2 Free accounts are limited to 10 GB of R2 storage.
3 Free accounts are limited to 5 GiB of database storage.
4 Free accounts are limited to 500 MiB per database.
5 Refer to the R2 documentation for more details on R2's consistency model.
Workers KV is an eventually consistent key-value data store that caches on the Cloudflare global network.
It is ideal for projects that require:
- High volumes of reads and/or repeated reads to the same keys.
- Per-object time-to-live (TTL).
- Distributed configuration.
To get started with KV:
- Read how KV works.
- Create a KV namespace.
- Review the KV Runtime API.
- Learn about KV Limits.
R2 is S3-compatible blob storage that allows developers to store large amounts of unstructured data without egress fees associated with typical cloud storage services.
It is ideal for projects that require:
- Storage for files which are infrequently accessed.
- Large object storage (for example, gigabytes or more per object).
- Strong consistency per object.
- Asset storage for websites (refer to caching guide)
To get started with R2:
- Read the Get started guide.
- Learn about R2 Limits.
- Review the R2 Workers API.
Durable Objects provide low-latency coordination and consistent storage for the Workers platform through global uniqueness and a transactional storage API.
-
Global Uniqueness guarantees that there will be a single instance of a Durable Object class with a given ID running at once, across the world. Requests for a Durable Object ID are routed by the Workers runtime to the Cloudflare data center that owns the Durable Object.
-
The transactional storage API provides strongly consistent key-value storage to the Durable Object. Each Object can only read and modify keys associated with that Object. Execution of a Durable Object is single-threaded, but multiple request events may still be processed out-of-order from how they arrived at the Object.
It is ideal for projects that require:
- Real-time collaboration (such as a chat application or a game server).
- Consistent storage.
- Data locality.
To get started with Durable Objects:
- Read the introductory blog post ↗.
- Review the Durable Objects documentation.
- Get started with Durable Objects.
- Learn about Durable Objects Limits.
D1 is Cloudflare’s native serverless database. With D1, you can create a database by importing data or defining your tables and writing your queries within a Worker or through the API.
D1 is ideal for:
- Persistent, relational storage for user data, account data, and other structured datasets.
- Use-cases that require querying across your data ad-hoc (using SQL).
- Workloads with a high ratio of reads to writes (most web applications).
To get started with D1:
- Read the documentation
- Follow the Get started guide to provision your first D1 database.
- Review the D1 client API.
Cloudflare Queues allows developers to send and receive messages with guaranteed delivery. It integrates with Cloudflare Workers and offers at-least once delivery, message batching, and does not charge for egress bandwidth.
Queues is ideal for:
- Offloading work from a request to schedule later.
- Send data from Worker to Worker (inter-Service communication).
- Buffering or batching data before writing to upstream systems, including third-party APIs or Cloudflare R2.
To get started with Queues:
- Set up your first queue.
- Learn more about how Queues works.
Hyperdrive is a service that accelerates queries you make to existing databases, making it faster to access your data from across the globe, irrespective of your users’ location.
Hyperdrive allows you to:
- Connect to an existing database from Workers without connection overhead.
- Cache frequent queries across Cloudflare's global network to reduce response times on highly trafficked content.
- Reduce load on your origin database with connection pooling.
To get started with Hyperdrive:
- Connect Hyperdrive to your existing database.
- Learn more about how Hyperdrive speeds up your database queries.
Analytics Engine is Cloudflare's time-series and metrics database that allows you to write unlimited-cardinality analytics at scale using a built-in API to write data points from Workers and query that data using SQL directly.
Analytics Engine allows you to:
- Expose custom analytics to your own customers
- Build usage-based billing systems
- Understand the health of your service on a per-customer or per-user basis
- Add instrumentation to frequently called code paths, without impacting performance or overwhelming external analytics systems with events
Cloudflare uses Analytics Engine internally to store and product per-product metrics for products like D1 and R2 at scale.
To get started with Analytics Engine:
- Learn how to get started with Analytics Engine
- See an example of writing time-series data to Analytics Engine
- Understand the SQL API for reading data from your Analytics Engine datasets
Vectorize is a globally distributed vector database that enables you to build full-stack, AI-powered applications with Cloudflare Workers and Workers AI.
Vectorize allows you to:
- Store embeddings from any vector embeddings model (Bring Your Own embeddings) for semantic search and classification tasks.
- Add context to Large Language Model (LLM) queries by using vector search as part of a Retrieval Augmented Generation (RAG) workflow.
- Filter on vector metadata to reduce the search space and return more relevant results.
To get started with Vectorize:
- Create your first vector database.
- Combine Workers AI and Vectorize to generate, store and query text embeddings.
- Learn more about how vector databases work.
Cloudflare Workers offers a SQLite-backed serverless database product - D1. How should you compare SQLite in Durable Objects and D1?
D1 is a managed database product.
D1 fits into a familiar architecture for developers, where application servers communicate with a database over the network. Application servers are typically Workers; however, D1 also supports external, non-Worker access via an HTTP API ↗, which helps unlock third-party tooling support for D1.
D1 aims for a "batteries included" feature set, including the above HTTP API, database schema management, data import/export, and database query insights.
With D1, your application code and SQL database queries are not colocated which can impact application performance. If performance is a concern with D1, Workers has Smart Placement to dynamically run your Worker in the best location to reduce total Worker request latency, considering everything your Worker talks to, including D1.
SQLite in Durable Objects is a lower-level compute with storage building block for distributed systems.
By design, Durable Objects are accessed with Workers-only.
Durable Objects require a bit more effort, but in return, give you more flexibility and control. With Durable Objects, you must implement two pieces of code that run in different places: a front-end Worker which routes incoming requests from the Internet to a unique Durable Object, and the Durable Object itself, which runs on the same machine as the SQLite database. You get to choose what runs where, and it may be that your application benefits from running some application business logic right next to the database.
With SQLite in Durable Objects, you may also need to build some of your own database tooling that comes out-of-the-box with D1.
SQL query pricing and limits are intended to be identical between D1 (pricing, limits) and SQLite in Durable Objects (pricing, limits). During SQLite in Durable Objects beta, Storage per Durable Object is 1GB, which will be raised to mirror storage per D1 database (10GB) by general availability.
Cloudflare Workers KV provides an eventually consistent global key-value store that caches data throughout Cloudflare's network to provide low read latency for hot reads to keys. This is ideal for storing data that is repeatedly read by your Workers, such as configuration data, user preferences, cached values, etc. Workers KV can sustain high read throughput (unlimited requests per second per key) with <5ms latency globally for hot reads. Workers KV is eventually consistent, so writes may take up to 60 seconds to propagate through Cloudflare's network by default.
Cloudflare D1 provides a SQL database that supports relational data modeling and querying. D1 supports snapshot isolation consistency and is ideal for workloads that store user data or general web application data.
- Use Workers KV if you need to store and access configuration data that will be read by Workers frequently, is written infrequently (<1 RPS per key) and can tolerate eventual consistency.
- Use D1 if you need to store general application data, need SQL access to your data, and require strong consistency (writes are immediately visible after being committed).
D1 is a standalone, serverless database that provides a SQL API, using SQLite's SQL semantics, to store and access your relational data.
Hyperdrive is a service that lets you connect to your existing, regional PostgreSQL databases and improves database performance by optimizing them for global, scalable data access from Workers.
- If you are building a new project on Workers or are considering migrating your data, use D1.
- If you are building a Workers project with an existing PostgreSQL database, use Hyperdrive.