Workers KV source centers consistency

I have heard that workers KV has two source centers, one at Europe and another at middle of America. I wanna know if in the following situation:
put(‘test’, ‘Europe’);
put(‘test’, ‘America’);
these two put operations happen at almost the same time, the first operation happened at Europe edge, the second operationhappened at American edge. In this case, they will update the same key at the same time in different centers.
If that is the case, how can KV keep the data consistency?

1 Like

I mean, is there any timestamp mechanism? or something like that.

1 Like

Last write wins. So in this case, ‘America’ would win.

1 Like

If last write wins is not suitable for your use case, you can check out Workers Durable Objects.

Sorry, I didn’t make it clear, I mean if the same key has been updated at the same time at different source centers, how do it keep the time consistency. How to judge the “last one”.

IIRC (don’t quote me on this) there is a timestamp attached so it will accept the newer value. If the writes happened at the same millisecond, I’m not sure what would happen there. When handling KV you kind of expect some inconsistency sometimes due to value caching and such.

As already mentioned, Durable Objects are great for a solid consistency.

I recommend joining the Discord, lots of other developers using Workers and lots of info on inner workings. You can join here: https://workers.community

2 Likes

If two source centers (American center and Europe center) has been updated at the same time. How to achieve the last win. I mean, which one is the last one. Is it depends on timestamp or something?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.