You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/kv/concepts/how-kv-works.mdx
+16-7Lines changed: 16 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,13 +7,12 @@ sidebar:
7
7
8
8
KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare's data centers after access.
9
9
10
-
KV supports exceptionally high read volumes with low latency, making it possible to build highly dynamic APIs.
11
-
12
-
While reads are periodically revalidated in the background, requests which are not in cache and need to hit the centralized back end can experience high latencies.
10
+
KV supports exceptionally high read volumes with low latency, making it possible to build dynamic APIs that scale thanks to KV's built-in caching and global distribution.
11
+
Requests which are not in cache and need to hit the centralized back end can experience higher latencies.
13
12
14
13
## Write data to KV and read data from KV
15
14
16
-
When you write to KV, your data is written to central data stores. Your data is not sent automatically to every location’s cache.
15
+
When you write to KV, your data is written to central data stores. Your data is not sent automatically to every location's cache.
17
16
18
17

19
18
@@ -26,7 +25,7 @@ A hot read means that the data is cached on Cloudflare's edge network using the
26
25
27
26

28
27
29
-
Frequent reads from the same location return the cached value without reading from anywhere else, resulting in the fastest response times. KV operates diligently to keep the latest value in the cache by refreshing from upper tiers and the central data stores in the background.
28
+
Frequent reads from the same location return the cached value without reading from anywhere else, resulting in the fastest response times. KV operates diligently to update the cached values by refreshing from upper tier caches and central data stores tiers before cache expires in the background.
30
29
31
30
Refreshing from upper tiers and the central data stores in the background is done carefully so that assets that are being accessed continue to be kept served from the cache without any stalls.
32
31
@@ -44,8 +43,6 @@ Changes are usually immediately visible in the Cloudflare global network locatio
44
43
45
44
Negative lookups indicating that the key does not exist are also cached, so the same delay exists noticing a value is created as when a value is changed.
46
45
47
-
KV does not perform like an in-memory datastore, such as [Redis](https://redis.io). Accessing KV values, even when locally cached, has significantly more latency than reading a value from memory within a Worker script.
48
-
49
46
## Consistency
50
47
51
48
KV achieves high performance by being eventually-consistent. At the Cloudflare global network location at which changes are made, these changes are usually immediately visible. However, this is not guaranteed and therefore it is not advised to rely on this behaviour. In other global network locations changes may take up to 60 seconds or more to be visible as their cached versions of the data time-out.
@@ -60,6 +57,18 @@ If you need stronger consistency guarantees, consider using [Durable Objects](/d
60
57
61
58
An approach to achieve write-after-write consistency is to send all of your writes for a given KV key through a corresponding instance of a Durable Object, and then read that value from KV in other Workers. This is useful if you need more control over writes, but are satisfied with KV's read characteristics described above.
62
59
60
+
## Comparison with other key-value stores
61
+
62
+
Workers KV is optimized to provide edge data to Workers running across Cloudflare's network. KV can provide low-latency access to data for optimal Workers performance.
63
+
64
+
However, since Workers and Workers KV's central stores are not co-located by default, writes and uncached reads can have more latency than a typical web architecture using a co-located in-memory store like [Redis](https://redis.io).
65
+
66
+
For most scenarios, Workers KV and Workers' default global placement are optimal, especially for read-heavy applications. These can include serving static assets, caching, storing application configurations or user preferences, implementing allow-lists/deny-lists, and more.
67
+
68
+
For scenarios that are more write-heavy and less cacheable, using Workers with [smart placement](/workers/configuration/smart-placement/) and Workers KV or [Durable Objects](/durable-objects/) can reduce network latency incurred for writes.
69
+
70
+
Workers KV also has [limits](/kv/platform/limits/) such as 1 write per key per second and a minimum [`cacheTtl`](/kv/api/read-key-value-pairs/#cachettl-parameter) of 60 seconds as an eventually consistent data store which provide different performance and characteristics than other key-value stores.
71
+
63
72
## Security
64
73
65
74
Refer to [Data security documentation](/kv/reference/data-security/) to understand how Workers KV secures data.
0 commit comments