miniflare icon indicating copy to clipboard operation
miniflare copied to clipboard

Emulate racing in KV

Open GregBrimble opened this issue 4 years ago • 1 comments

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:

  1. POST /increment -> 1 (machine 1)
  2. POST /increment -> 2 (machine 1)
  3. POST /increment -> 3 (machine 1)
  4. POST /increment -> 1 (machine 2)
  5. POST /increment -> 4 (machine 1)
  6. POST /increment -> 5 (machine 1)
  7. POST /increment -> 1 (machine 3)
  8. POST /increment -> 2 (machine 2)

Expire each machine's cache after 60s and find the most recently written to value across the network.

GregBrimble avatar Dec 18 '21 15:12 GregBrimble

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 🎉

mrbbot avatar Jan 01 '22 00:01 mrbbot