Workers KV: a simple key-value store at the edge
Workers KV
What it is
Workers KV is Cloudflare’s simple key-value store for Workers. You store a value under a string key, then read, list, or delete it from your Worker. Values are usually strings or small blobs (for example a short JSON string). There are no tables, no joins, and no SQL.
KV is globally distributed and eventually consistent. A write in one place may take a short time to show everywhere. That is fine for config flags, caches, and lookups. It is a poor fit if every write must be instantly visible worldwide or you need relational queries.
You create a KV namespace in the dashboard (or with Wrangler), then bind it to a Worker. In wrangler.toml that looks like a [[kv_namespaces]] block with a binding name such as MY_KV. In the script you then call something like env.MY_KV.get(key), env.MY_KV.put(key, value), list, or delete. The binding name is how the Worker finds that namespace — not the namespace’s display title alone.
Why it matters
Small Workers on kosan.xyz often need a little stored state without a full database: a feature flag, a short cache, a rate counter, lesson progress, or a lookup table. KV fits those cases. It is not a replacement for Postgres or D1 when you need relations, transactions, or heavy write traffic.
Knowing when to reach for KV stops two common mistakes: stuffing config into the Worker script when a key would do, or trying to treat KV like a SQL database. For a GP stack with many tiny apps, the right store for a tiny string is often KV; the right store for structured rows is something else (for example D1).
Bindings are per Worker. Adding a KV namespace to one project does not give every other Worker access. Always bind only to the Worker you mean, and never attach a learning namespace to a live app.
On your account
This tutor (cloudflare-tutor on cloudflare.kosan.xyz) still stores every lesson in the LESSONS array inside worker.js. There is no KV binding in its wrangler.toml. Redeploying updates the script; nothing is read from KV yet. That is a deliberate simple design for a static lesson desk.
A different small kosan.xyz Worker might bind a namespace and store a last-seen timestamp, a short JSON blob, or a cache flag under keys you choose. That is the kind of state KV is good for — small, keyed, and fine with eventual consistency.
Elsewhere you may already use D1 for something more relational (for example heartbeat-style data). KV is not D1: no SQL, no joins, different consistency. Pick KV for simple get/put by key; pick D1 (or another database) when you need queries across rows. This lesson does not bind KV to cloudflare-tutor or any live app.
Do this yourself
These stay in the dashboard, on your side. This site does not change DNS, routes, or other Workers.
- Open the Cloudflare dashboard → Workers & Pages → KV (wording may say KV namespaces). Note whether any namespaces already exist. Read only. Do not create, rename, or delete anything yet, and do not open bindings on cloudflare-tutor, ainews, aiweekly, or other live apps.
- Optional throwaway only: create a KV namespace named only tutor-kv-lesson. If you want to try get/put, create a throwaway Worker named only tutor-kv-lesson, bind that namespace to it (for example as MY_KV), put one key such as hello with value lesson6, read it back, then delete that same Worker and that same KV namespace. Never bind KV to cloudflare-tutor, ainews, aiweekly, or other live apps.