Test, observe, and operate KV
Monitor usage and recover
Track reads, writes, storage, errors, and key ownership while keeping an authoritative rebuild path for cache data.
8 minute lesson
A KV namespace in production needs the same operational care as any datastore: you should know what is in it, who owns it, how much it costs, and how you would rebuild it.
Start with names. Name namespaces by application and environment — myapp-config-production, myapp-config-preview — so nobody has to guess what my-namespace-2 holds. Record who owns the key format and the retention policy. Six months from now, someone will ask whether user:* keys can be deleted, and “ask the person who left” is not an answer.
Watch the numbers that bill you
Monitor operation volume, storage, latency, and Worker errors against current limits and pricing. Reads, writes, deletes, and lists are billed separately, and storage accumulates. The dashboard shows per-namespace analytics; check them against what you expect. A read count ten times your traffic usually means a loop is reading per item instead of once per request.
You can also inspect a namespace directly:
npx wrangler kv key list --binding CONFIG --remote | head
npx wrangler kv key get --binding CONFIG feature-flags --remote
Alert on error rates in the Workers that use the namespace, because that is where KV failures surface.
Keep a rebuild path
If KV is a cache, document how to rebuild it from the source of truth. If it stores configuration, keep versioned source or an export path. The recovery plan for derived data is not backup — it is regeneration:
node scripts/build-config.mjs > config.json
npx wrangler kv bulk put config.json --binding CONFIG --remote
# Success! Uploaded 214 key-value pairs
Here the JSON file lives in git, and the namespace is disposable by design. Losing it costs one command.
Deleting is the dangerous operation
Never delete a shared namespace until every binding and deployment is checked. Preview environments, old deployments, and other Workers may still bind it, and the failure appears in their logs, not where you ran the delete.
Now rebuild a disposable practice namespace from a small versioned configuration file using kv bulk put, then switch a preview binding to the new namespace and verify the application reads from it.
Lesson completed