Cloudflare Workers KV and rate limiting

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?

I see a lot of issues with using Workers and KV for rate-limiting, like you pointed out, last-write-wins is always the case for CF KV. You can only write to a single value 1 time per second. It’s also very expensive, since 1M writes to KV costs 5$.

I’d suggest choosing something high-performance like Golang for this, which can handle thousands of requests per second on a 5$ VPS.