Hacker News new | ask | show | jobs
by vlakreeh 934 days ago
I highly recommend anyone using this to use a Durable Object https://developers.cloudflare.com/durable-objects/ for writes as this project doesn't seem to have consistency guarantees. If the Worker that writes to a collection happens to both do a write at the same time the data will be whatever the last Worker to write set it to.

Very cool library for read-centric use cases but I'd be very careful using this for use cases with frequent writes.

2 comments

I tried using durable objects and the API is sooooo confusing I ended up just moving to a firebase’s firestore.

I know they provide different features but I just needed a nosql type of storage so I didn’t care.

Couldn't the library implement a conditional operation using the etag, retrying if it fails? That should solve the consistency guarantee.

Ofc its a different matter if you write to the same key in the same file. But that could be solved with special method that allows you to do a setOrUpdate on a key in the json and when retrying the update method is executed again (allowing you to do increments or add a new item to an array) while guaranteeing consistency.

Consider the case of two workers both trying to write the same key at once. Which one should succeed?
If you use etags it's up to R2. I'm assuming R2 is consistent here.

So if you write to the same file twice, one write will succeed before the other and change the etag of the file, which should in theory cause the other request to R2 to fail because the etag you send with as conditional no longer matches.

Its up to your implementation. Which is very similar to any other "average" database ...