Choose a data or storage product for your use-case
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.
- 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.
Choose a storage product
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. |
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-prem. |
Performance and consistency
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 | 50GiB 3beta |
Storage grouping name2 | Namespace | Bucket | Durable Object | Database |
Maximum size per value | 25 MiB | 5 TiB per object | 128 KiB per value | 2 GiB per database |
Consistency model | Eventual: updates take up to 60s to be reflected | Strong (read-after-write)4 | 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 GiB of R2 storage. 3 Free accounts are limited to 5 GiB of database storage. 4 Refer to the R2 documentation for more details on R2’s consistency model.
Workers KV
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
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
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
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.
Queues
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
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.
Vectorize
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.