rhocfsandbox.com

demo: workers kv counter

a single global counter stored in workers kv. every visitor's click increments the same key from any colo. kv is eventually consistent globally, so a burst of clicks from different regions can briefly show stale reads. fine for counters, not for banking.

click a button…

# how it works

  1. page function /api/counter binds to kv namespace SITE_counter_kv
  2. GET reads the global_counter key
  3. POST reads, adds 1, writes it back
  4. no transaction, no lock. two writers racing can overwrite each other. that's kv.

# config

namespaceSITE_counter_kv
binding nameKV_COUNTER
keyglobal_counter
free tier100k reads/day, 1k writes/day, 1gb storage