/ Cases / Lodging / Bookings
Instant or request-to-book reservations, a calendar synced with Airbnb and an anti-overlap lock in the database: two people can't book the same night.
15 min
reconciliation with Airbnb
0
nights sold twice
/ The problem
Every booking went through Airbnb and its commission. Opening a direct channel came with a risk: selling the same night twice.
/ What we built
/ How it works
/ Real code
-- ── Bloqueos (Airbnb por iCal, manuales) ─────────────────────────────────
create table blocks (
property_id uuid not null references properties on delete cascade,
nights daterange not null, -- [inicio, fin)
source block_source not null default 'manual',
external_uid text, -- UID del VEVENT; para upsert idempotente
-- …
unique (property_id, source, external_uid)
);
-- …
-- ── Reservas propias ─────────────────────────────────────────────────────
create table bookings (
property_id uuid not null references properties on delete restrict,
nights daterange not null, -- [checkin, checkout)
status booking_status not null default 'hold',
source booking_source not null default 'web',
hold_expires_at timestamptz, -- solo mientras status = hold
-- …
constraint nights_valid check (lower(nights) < upper(nights)),
-- Nunca dos reservas vivas solapadas en la misma casa.
exclude using gist (property_id with =, nights with &&)
where (status in ('hold', 'pending_payment', 'confirmed'))
);
■ Airbnb blocks are imported idempotently by iCal UID, and the EXCLUDE constraint makes it impossible to store two overlapping bookings.
/ Stack