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-prem. |
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.