skip to content

As a platform lead, what rule would you set for which data a team may keep in Workers KV, and what evidence would make you move a dataset out of it?

level: principalimportance: should knowfreq 30%

answer

  1. read-heavy, written rarely
  2. how stale may a reader be
  3. who is allowed to write
  4. where the data must rest
  5. signals in errors and bills

basics

~20 s

Allow Workers KV only for data read far more than written, with one writer well under once a second per key, that tolerates reads a minute or more old. Move it out on 429s, lost updates, stale-read bugs or query-shaped access.

solid answer

~50 s

I would make the rule about access pattern rather than data type. KV is approved for flags, site configuration, allow and deny lists, cached responses and session-style lookups: read on most requests, written rarely by a single process, small enough for 512-byte keys and 25 MiB values, and safe if another location sees an old value for 60 seconds or more. Anything incremented per request, needing read-your-write across locations or an atomic update goes to a Durable Object; relational queries go to D1; large blobs go to R2. Each KV dataset names its writer, its `cacheTtl` and its expiry policy, and data with residency rules uses a namespace created with a jurisdiction. I would move a dataset when its logs show 429s, its write share of the bill grows, incidents trace to stale reads, or code starts scanning with `list()` to answer queries.

go deeper

for a junior

Know that KV suits data that is read often, written rarely, and allowed to be briefly out of date.

for a middle

Name the limits behind the rule: one write per second per key, propagation of 60 seconds or more, and the key, value and metadata sizes.

for a senior

Read 429s, lost updates, stale-read incidents and list() scans as evidence that a dataset is in the wrong store, and plan its move.

for a principal

Own the admission test, who may write, how staleness budgets and residency are recorded, and when an exception is acceptable, weighing one simple store against several correct ones.

## Why a lead needs a rule at all Workers KV is the easiest store on the platform to start with: one binding, `get()` and `put()`, no schema. That ease is the risk. A team that has a namespace for flags will put the next dataset there too, whether or not it fits, and KV's failure modes, stale reads and rate-limited writes, appear only under production traffic. A lead's job is to write down what is allowed, who owns the exceptions, and what evidence triggers a move. There is no single right line; the rule trades read latency everywhere against consistency and write capacity. ## The admission test A dataset may live in KV when all of these hold: 1. **Read-heavy.** It is read on many requests, often every one, and written rarely. Cloudflare's own guidance lists configuration, user preferences, allow-lists and deny-lists, cached data and static assets. 2. **Write rate well under one per second per key.** That is a hard platform limit; designs that approach it fail with 429 errors. 3. **Staleness is acceptable.** A reader in another location may see the previous value, or a not-found, for 60 seconds or more. The owner states how stale is tolerable, and that budget sets the `cacheTtl` (default 60 seconds, minimum 30). 4. **No atomic updates.** Nothing reads, modifies and writes back the same key from concurrent requests. 5. **It fits the limits.** Keys up to 512 bytes, values up to 25 MiB, metadata up to 1024 bytes. ## Where the rejected data goes | Need | Store | |---|---| | Counters, locks, per-user quotas, read-your-write | Durable Objects | | Relational queries, joins, filtering by fields | D1 | | Large files and media | R2 | | An existing database the company already runs | that database, reached through Hyperdrive | The choice among those stores is a wider decision with its own lessons; the KV rule only has to say what does not belong in KV. ## Operating rules for approved datasets - **One named writer.** The documentation's pattern for avoiding competing writes is a single writing process: an admin tool, a CI job, a Durable Object or the API. Request handlers read; they do not write shared keys. - **A key scheme with prefixes**, such as `flags:` and `site:eu:`, so `list()` and bulk deletes can target one dataset. - **Expiry on caches.** Cached responses carry `expirationTtl` so stale entries clean themselves up. - **Change procedure for flags.** Readers must accept both old and new values during a switch, and the runbook says a change can take a minute or more to reach every location. - **Automation targets `--remote` explicitly**, because Wrangler 4 runs KV commands against local storage by default. - **Residency.** A dataset under data-location rules goes in a namespace created with `--jurisdiction` (`eu`, `us` or `fedramp`). The jurisdiction can only be set when the namespace is created, and it controls where data is durably stored, not where it may be cached or read. ## Evidence that a dataset has outgrown KV A lead should ask for these signals and act on them: - **429 errors** from `put()` in Workers Logs or error tracking: some key is written too often. - **Lost or jumping values**, such as a counter that goes backwards: concurrent read-modify-write. - **Incidents caused by stale reads**, for example a user who changes a setting and sees the old one on the next page. - **Write share of the bill rising.** On the Paid plan a write costs $5.00 per million beyond the included million, ten times a read; a write-heavy namespace is paying for the wrong store. - **`list()` used as a query engine**, scanning a prefix to filter or count on every request. - **Values growing towards the size limits**, or metadata creeping past 1024 bytes. ## The tradeoffs a lead owns - **Simplicity against correctness.** One store for everything is easy to teach, but pushes consistency bugs into production. Several stores are more to operate, so the rule should keep the list short. - **Latency against freshness.** A long `cacheTtl` gives the fastest reads and the longest staleness; the owner of each dataset, not the platform team, should choose it. - **Migration cost.** Moving a dataset later means dual writes or a cutover; asking the admission questions at design review is cheaper than moving a hot dataset under load. The rule is a default, not a ban: an exception is fine when the owner writes down why the dataset passes the test anyway.

  • In Workers KV, a team needs EU-only storage for an existing namespace; can it add a jurisdiction to it?
    No. A jurisdiction can only be set when a namespace is created, with `wrangler kv namespace create <name> --jurisdiction eu`, the dashboard or the REST API, and cannot be added or changed afterwards. The team creates a new namespace, copies the data with a bulk upload, switches the binding, and accepts that cached copies may still exist outside the jurisdiction.
  • In Workers KV, when would you accept user preferences in KV even though users write them?
    When each user writes their own key rarely, so no key nears one write per second, and when a preference that takes up to a minute or more to show in another location is acceptable. If the product requires the change to appear on the very next page, that read-your-write need is the signal to keep preferences elsewhere.

  • Everything small goes in KV because it is the fastest store
  • Any request handler may write shared KV keys as long as it awaits put()
  • A jurisdiction can be added to a namespace later if regulations change
  • A short enough cacheTtl makes KV safe for read-your-write data
  • Write volume does not matter because KV is billed by storage

Assumes Workers KV as of 2026-10-10: namespace jurisdictions became generally available on 2 October 2026, the minimum cacheTtl is 30 seconds since January 2026, and Wrangler 4 defaults KV commands to local mode.