Workers KV — Cloudflare's distributed database

Ashcon Partovi
11 min readadvanced
--
View Original

Overview

Cloudflare's Workers KV is a globally distributed, eventually consistent key-value store designed for ultra-fast data retrieval. It allows developers to manage billions of key-value pairs with low latency, making it suitable for various applications including mass redirects and user authentication.

What You'll Learn

1

How to implement mass redirects using Workers KV

2

Why eventual consistency is beneficial for global applications

3

When to use expiring keys for temporary data storage

Prerequisites & Requirements

  • Basic understanding of key-value stores and distributed systems
  • Familiarity with Cloudflare Workers(optional)

Key Questions Answered

What is Workers KV and how does it function?
Workers KV is a distributed, eventually consistent key-value store that operates across Cloudflare's global edge network. It allows developers to store billions of key-value pairs and access them with ultra-low latency, making it ideal for applications requiring fast data retrieval.
What are the benefits of using Workers KV for application development?
Using Workers KV provides ultra-fast read speeds, with a median of 12 ms, and ensures data availability across over 175 edge data centers. This makes it suitable for applications that require quick access to data while being resilient to regional outages.
How can I implement bulk writes in Workers KV?
Bulk writes can be implemented using a new endpoint in the Cloudflare API, allowing developers to upload up to 10,000 key-value pairs in a single PUT request. This simplifies the process of importing existing data into Workers KV.
What are the pricing details for Workers KV?
The pricing for Workers KV includes $0.50 per GB of data stored, $0.50 per million reads, and $5 per million write, list, and delete operations. Each account includes 1 GB of storage and 10 million reads at no charge.

Key Statistics & Figures

Median read speed
12 ms
This performance metric highlights the efficiency of Workers KV in providing quick data access.
Data availability across edge data centers
175+
This indicates the extensive reach of Workers KV, ensuring data is accessible globally.
Value size limit
2 MB
This increase from the previous limit of 64 kB allows for more substantial data storage in Workers KV.

Technologies & Tools

Database
Workers Kv
Used for storing and retrieving key-value pairs globally across Cloudflare's edge network.
Backend
Cloudflare Workers
Allows developers to run JavaScript at the edge, enabling dynamic responses and data manipulation.

Key Actionable Insights

1
Utilize Workers KV for applications that require fast data access and global availability.
This is particularly useful for applications like user authentication and mass redirects, where low latency is crucial for user experience.
2
Implement bulk writes to streamline the process of importing large datasets into Workers KV.
This can save significant time and effort when transitioning existing applications to use Workers KV for data storage.
3
Consider using expiring keys for temporary data that needs to be automatically deleted after a set duration.
This feature is beneficial for managing user sessions or temporary flags without manual cleanup.

Common Pitfalls

1
Assuming immediate consistency when writing to Workers KV can lead to unexpected behavior.
Due to eventual consistency, users may read stale data immediately after a write operation, which can be problematic in scenarios requiring real-time accuracy.

Related Concepts

Distributed Systems
Eventual Consistency
Key-value Stores
Cloudflare Workers