KV - Some clients get null value for existing key.

This is VERY weird. I've got a simple link shortening service. On the same network, two different clients calling GET http://<URL>/slug This calls env.SHORTENED.get(slug) on the worker. For one client this results in null (and 404) For the other client the key is found successfully (and 301 to full URL happens). Looks like this is not very frequent but has happened on more than one occasion on more than one device. Also, this is intemittent, sometimes the request from the problematic device is successful. Any help or ideas for what to try to debug this would be greatly appreciated. Thanks!
14 Replies
johtso
johtso6mo ago
Does it match the expected behaviour? How long after being written is the key being read? https://developers.cloudflare.com/kv/reference/how-kv-works/#consistency
Cloudflare Docs
How KV works · Cloudflare Workers KV
KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare’s …
johtso
johtso6mo ago
If it's important that the written data is available everywhere immediately, D1 might be a better option
liorsbg
liorsbgOP6mo ago
Read happens 3-5 seconds after write. write and read are (throretically) from the same location since they're made from the same network. Could a plausible explanation be that the problem device is (for example) on a VPN and therefore reading from a different location to which the new key has not propagated to?
johtso
johtso6mo ago
There should be a way to see where a worker is running request.cf.region
liorsbg
liorsbgOP6mo ago
I see it, write and failed read are from same colo
johtso
johtso6mo ago
Interesting From the page I linked "At the Cloudflare global network location at which changes are made, these changes are usually immediately visible. However, this is not guaranteed and therefore it is not advised to rely on this behaviour."
liorsbg
liorsbgOP6mo ago
I see, but the key is visible when a different device on the same network calls the same endpoint In other words: same worker (assumed), same region (confirmed), same key, different result
johtso
johtso6mo ago
I guess because it's not cached so it fetched the real result
liorsbg
liorsbgOP6mo ago
not sure i follow
johtso
johtso6mo ago
"Visibility of changes takes longer in locations which have recently read a previous version of a given key (including reads that indicated the key did not exist, which are also cached locally)."
liorsbg
liorsbgOP6mo ago
So reading that a key does not exist cahces the null result for that key?
johtso
johtso6mo ago
If you check if a key exists the "does not exist" result is cached locally
liorsbg
liorsbgOP6mo ago
Interesting
johtso
johtso6mo ago
That's what it sounds like from the documentation anyway
Want results from more Discord servers?
Add your server