workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

[Feature] All-or-nothing multi-put operation for R2 bucket

Open rozbb opened this issue 1 month ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Description

I have an application whose state contains two variables, A and B. Both are stored in R2 at different keys. For my use case, it is necessary that every time I write a new value of A, I also write a new value of B. The application would be in an illegal state if only one variable were updated without the other.

Currently, there isn't a way for me to put two values in a Bucket such that either a) both values are successfully written, or b) both values fail to write.

An all-or-nothing multi-put feature would be very helpful. Another way to view this is as a small subset of a transactions API.

cc @guybedford

rozbb avatar Nov 18 '25 03:11 rozbb

A kind of nasty workaround is to have a third key C. This key contains "flip" or "flop". Rather than storing "A" and "B", the program stores "A_flip" and "B_flip", or "A_flop" and "B_flop". The variable C is only updated between "flip" and "flop" if both the A and B writes succeed.

rozbb avatar Nov 18 '25 03:11 rozbb

That workaround is indeed quite nasty. I believe we have something like this feature in javaascript: grouping multiple reads/writes to storage into a single transaction. If so, I think it makes sense to have parity with rust.

cjpatton avatar Nov 19 '25 16:11 cjpatton