Workers KV write pricing: what a write on every request costs
KV writes cost $5 per million. A write on every request is easy to ship by accident and adds up to real money.
On Workers Paid, KV reads are $0.50 per million and writes are $5 per million (after the included usage). Most of the time that's fine because KV is built for read-heavy stuff.
The trap is a "small" write on every request. A per-session last-seen timestamp, a per-user cache entry, that kind of thing. At 100 requests per second across different keys that's 8.64M writes a day, about $43 a day, or ~$1,300 a month for data nobody reads.
And for a shared counter it doesn't work at all. KV is eventually consistent and allows about one write per second to the same key, so most of those writes just fail. Not a good counter, then.
What to do instead
- Counters or strict global limits: a Durable Object. The Workers rate limiting binding is fine for approximate, per-location limits.
- Last-seen style data: only write when the value actually changed, or batch it.
- Grep for
.put(in your request handlers. Seriously, it takes a minute.