I’m trying to build a rate limiting mechanism for an API using Workers KV, and have a question in this regard.
My users are allowed to make a certain number of requests per day to the API, and this limit can vary between each user.
The Workers KV documentation mentions:
New key-value pairs are immediately available everywhere, but value changes may take up to 60 seconds to propagate.
Imagine a situation where the key k holding the number of requests a given user made is currently 0. The user makes 50 requests which are routed to an edge location A, which means at A, k = 50.
Since the changes take some time to propagate, the value of k at another edge location B might be 0 for some time.
The user now makes 20 requests which get routed to B. (The user may have multiple servers to make requests, so this is fairly plausible.) Now, B would have the value k = 20.
Would these values be reconciled later on, i.e. when the edge locations sync up, the combined value would be 70, or does it follow a last-write-wins strategy, and k = 20 would win?
This API would be a paid product, so losing the number of calls they made isn’t ideal as my usage plans would be based around this.
Anyway, did I understand this correctly, and if not, can someone tell me how CloudFlare would behave in this scenario?