Concurrency · NeetoCal
Two people, one slot. Only one booking.
With over a million bookings, two visitors clicking the same slot within milliseconds is a daily event. A check in Ruby can't win that race, and with paid bookings the card may already be charged.
- The database refuses it. Our engineers added a PostgreSQL exclusion constraint on time ranges, so no code path, job or console session can ever create a double booking.
- Even the deadlock is handled. Two inserts can deadlock while Postgres checks the constraint. NeetoCal recognises that exact case and shows the visitor a clean "slot just got taken" message.
- Paid but lost the race. The customer gets 10 hours to pick a new time, then an automatic, idempotent refund.
- Row locks where they matter. Group seats, discount-code limits and saved-card charges never oversell.
What you getEngineers who push correctness into the database, where races can't get past it. Essential for booking, inventory, ticketing and payments.
exclusion_constraint "user_id WITH =, is_overridden WITH =, tsrange(starts_at, ends_at) WITH &&", using: :gist, name: "booking_slot_should_not_overlap"
The rule lives in Postgres, so it holds everywhere.