Emulate racing in KV
Just an idea, and a relatively big project, so I have no idea if you'd want to support this in Miniflare, but might be interesting to have an option to emulate the quirks of racing KV writes.
Requests to a single colo can be raced when they hit a different machine, and of course, requests to different colos can be raced.
I imagine you'd want a something like 1/5 requests to 'hit a different machine'. This would be a good default behavior to allow people to set expectations of KV when they're prototyping something locally, or you could hide it away behind a flag if you don't want a breaking change.
TL;DR:
- POST /increment -> 1 (machine 1)
- POST /increment -> 2 (machine 1)
- POST /increment -> 3 (machine 1)
- POST /increment -> 1 (machine 2)
- POST /increment -> 4 (machine 1)
- POST /increment -> 5 (machine 1)
- POST /increment -> 1 (machine 3)
- POST /increment -> 2 (machine 2)
Expire each machine's cache after 60s and find the most recently written to value across the network.
Hey! 👋 I like this idea, though I'm not sure about adding non-determinism to tests by default, even though this probably means bugs in code. For development though via the CLI, it could be a good default. I feel like if it wasn't the default, people wouldn't enable it.
As for the implementation, we could probably do it as a decorator on the KVNamespace class. Maybe something to look at once V2 is fully-released?
Happy new year btw 🎉