Decrementing a count property by 1 with KV and Promise.all

Hi!

I'm using workers KV to keep track of # of credits a user has (the count property).

i.e. {user1234: {credits: 10}}

In my client application, I'm using Promise.all to make multiple requests to an endpoint on my Worker /decrementCreditsByOne which does what the name implies.

It works great locally, but on the deployed worker, The count loses track.

My app frequently uses Promise.all to call /decrementCreditsByOne at least 10 times.

the function essentially gets the JSON from KV using the unique key, decrement the credits by 1, then puts the value back in with the updated credits.

Is KV the wrong choice here? Would Durable Objects, or D1 be better? What would you recommend? Should this work and my logic is just wrong?

Also, I noticed timestamps aren't really a thing with KV. They aren't a requirement for my app but would be nice to have!
Was this page helpful?