Handling concurrent requests and delayed database writes

When two requests run at the same time, what supported method stops them from claiming the same slot? And if one times out, how do we know its database write won’t finish later and interfere with the next request?

Short version: Velo has no “lock” for a slot, so the trick is to make the database itself refuse the second claim. Give every slot a deterministic id (for example the date plus the time, like 2026-11-0514:00) and claim it with wixData.insert() instead of “check, then save”. Inserting an item with an _id that already exists fails, so when two requests race, one insert wins and the other gets an error you can turn into “sorry, that slot just got taken”. The usual check-then-write pattern is what lets both through, because both checks pass before either write lands.

On timeouts: a backend call that times out on the client side can still finish on the server, so you can’t assume a timed-out request did nothing. Make the write safe to repeat. Store a requestId (generate it in the page, send it with the call) on the item. If the user retries or the next request comes in, read the slot first. If it exists and has your requestId, the earlier attempt actually succeeded, so just return success. If it has a different requestId, it’s taken. With a fixed _id per slot there is nothing left to “interfere later”, the late write either created the item once or hit the duplicate error.

Caveat: I’m going from how insert and duplicate _id behave in Velo, so test it by firing two calls at once from a small test page before relying on it for real bookings.