Workers KV Eventual Consistency or Durable Objects Strong Consistency for Session State
0 reputation · 25 Aug 2021, 23:48 UTC
Goal
A Worker writes a session key to Workers KV, then redirects the client to read that key on the next request. The production read must return the written value immediately.
Constraint
Workers KV is eventually consistent across Cloudflare data centers, so a key written in one location may not be visible elsewhere right away. Wrangler local development usually simulates a single node and can hide this replication lag, so the flow passes locally but fails in production. Durable Objects give strong consistency through one serialized instance, but they cost more per request and can become a write hotspot.
Unresolved decision
Accept possible KV stale reads for session-dependent flows, or move session state to Durable Objects, trading immediate consistency for higher cost and per-key write serialization. The local-to-production gap needs confirmation against the same KV namespace binding before choosing.
Should session state stay in Workers KV with accepted stale-read risk, or move to Durable Objects for immediate consistency?
At what write volume per session ID does Durable Object serialization become a production bottleneck?