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
- page function
/api/counterbinds to kv namespaceSITE_counter_kv - GET reads the
global_counterkey - POST reads, adds 1, writes it back
- no transaction, no lock. two writers racing can overwrite each other. that's kv.
# config
| namespace | SITE_counter_kv |
| binding name | KV_COUNTER |
| key | global_counter |
| free tier | 100k reads/day, 1k writes/day, 1gb storage |