Menu

How I stop double bookings in a booking app: let Postgres refuse them
📰

How I stop double bookings in a booking app: let Postgres refuse them

DEV Community: reactnative·Ahmed Farouk·27 days ago
#fRprDJ9y
#devtoreactnative#devto#dev#booking#time
Long article (417 words) — no AI summary yet.
Reading 0:00
15s threshold

Every salon, barber and clinic wants a booking app, and every booking app has the same hard part: availability and double-booking. I built a kit around that problem, and this is the design decision that mattered most.

Let the database refuse double bookings

The tempting way is to check "is this slot free?" in the app, then write the booking. Two people tapping the same slot at the same moment can both pass that check.

So the rule lives in Postgres, in two places:

Availability is a database function. The app never computes free slots. It calls get_available_times and shows what comes back.

Overlaps are impossible by constraint. The bookings table has an exclusion constraint (using the btree_gist extension) so two active bookings for the same staff member cannot overlap in time. If a race slips past everything else, the database rejects the second insert and the app shows a clear "that time was just taken" message.

The app only ever calls functions such as create_booking .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.