Urgent.News

What's breaking now, across thousands of outlets.

Editions

Tech

I Solved Double-Booking Without Locks — Using One PostgreSQL Constraint

TL;DR I built Randevu, a free appointment booking system for Turkish barbershops and hair salons. The UI was the easy part. The hard part was making sure two customers can never grab the same time slot, even when they both hit "confirm" in the same millisecond. Instead of application-level locks, a job queue, or "check-then-insert and hope," I pushed the guarantee down into the database itself…

Randevu is a free appointment booking system designed for Turkish barbershops and hair salons. The UI was straightforward, but the core challenge was preventing two customers from booking the same time slot, even if they both clicked "confirm" simultaneously. Instead of relying on application-level locks or job queues, Randevu employed a single PostgreSQL EXCLUDE constraint to guarantee that no two appointments could overlap.

By using the tstzrange type and the btree_gist extension, the constraint checked for overlapping time ranges for a specific barber, ensuring that insertions could only succeed if the new appointment did not clash with existing ones. This approach eliminated the need for any application-level locks or background serialization, as the database itself enforced the rule, preventing any race conditions.

Additionally, Randevu addressed the issue of appointment timeouts dynamically by calculating the expiration duration based on the barber's actual working hours, rather than using a fixed timeout. To handle WhatsApp notifications and push alerts without relying on the WhatsApp Business API or Firebase, Randevu utilized direct browser push API communication via VAPID keys, streamlining the process and avoiding extra vendor integrations.

To prevent automated spam submissions, Cloudflare Turnstile provided an invisible CAPTCHA-like barrier, allowing real users to book appointments while filtering out bots. The entire system was built using Next.js 16 and TypeScript, backed by Prisma and PostgreSQL hosted on Neon, with the EXCLUDE constraint enforced at the database level.

The project aims to provide a zero-cost infrastructure solution for small businesses, with the free offering available at randevu-five.vercel.app and the source code available on GitHub.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Friday 21 August →