Introduction
Next to Workers, KV is one of the more important offerings from Cloudflare. It's a simple key-value store with the ability to list keys and automatically expire entries. Data is distributed to exit nodes worldwide, can be integrated into Workers directly, and read requests scale up (practically) to infinity without breaking.
You can interact with KV from within a Worker, or you can use the Cloudflare API. This means it is really easy to, for example, push up generated data sets or files as part of a deployment step, and then access those in the Worker as part of business logic for request handling.
Limitations
Because KV is a relatively simple data store, it's not too surprising that there aren't many foot guns TODO add link to terminology page
. Most issues are due to the natural technical limitations of what a simple key-value store can do, and behind the scenes limitations that Cloudflare has.
- Keys are strings only. Using
.
or..
is not allowed. Maximum key length is 512 bytes. (For reference, MongoDB id limit is 1024 bytes. Of course a SHA-512 would be 512 bytes, which may indicate a sneak peek behind the Cloudflare covers.)
https://www.mongodb.com/docs/manual/reference/limits/
Writing Data
You add data to KV a few possible ways, mostly though it's just "one entry at a time" versus "many entries at once". The important limitations are:
Reading Data
TODO