Back to docs
Recipe

Cloudflare KV Primer

Global low-latency key-value storage at the edge — ideal for licensing state, session tokens, and rate-limit counters.

What is KV?

Cloudflare Workers KV is a eventually-consistent key-value store replicated across Cloudflare's global network. Reads are served from the closest edge location with sub-10ms latency. Writes propagate globally within 60 seconds.

Why KV for licensing?

  • Session tokens — store JWT refresh tokens keyed by user ID for instant revocation.
  • Rate limiting — atomic increment counters with TTL expiry, no Redis needed.
  • License state — cache active entitlements so your origin stays idle during spikes.
  • Feature flags — toggle features per-tenant without a database migration.

Data model

KV is flat — string keys map to arbitrary byte values. Structure comes from your key naming convention. Use colons as delimiters:

license:user:abc123:entitlements
session:user:abc123:refresh
ratelimit:ip:203.0.113.5:login

Consistency model

KV is eventually consistent. A write in London may not be visible in Tokyo for up to 60 seconds. For licensing, this means: write revocation tokens from one region, expect a propagation delay before all edge nodes enforce the block. If you need strong consistency, pair KV with Durable Objects for the authoritative write path.

TTL and expiration

Every write accepts an optional expirationTtl in seconds. Expired keys are eventually removed — reads return null. Use TTLs aggressively: session tokens expire in 24h, rate-limit counters in 60s. This keeps your storage footprint small and predictable.

Next steps

Ready to wire KV into your Meridian stack? Continue to the implementation recipe for Workers integration with the licensing API.

Meridian tip: Prefix all licensing keys with your environment slug (prod, staging) to avoid cross-environment pollution during testing.