Prompt
How do I prevent double-booking when users connect external calendars?
Latest observation
Oct 15, 2026
OpenAI APIWeb search: off
To prevent double-booking with connected external calendars, use a sync + conflict-check + hold/lock approach rather than relying on a one-time import.
Core pattern
-
Import external busy times
- Connect via OAuth.
- Pull events from Google Calendar / Outlook / iCloud, etc.
- Treat external events as read-only availability blockers.
-
Continuously sync updates
- Use webhooks/subscriptions when available, plus periodic polling as a fallback.
- Keep your availability cache fresh so cancellations/reschedules are reflected quickly.
-
Check availability at booking time
- Before confirming, verify the requested slot against:
- your own bookings
- all connected calendars’ busy periods
- buffers, working hours, recurrence rules, time zones
- If the slot is no longer free, reject and offer alternatives.
- Before confirming, verify the requested slot against:
-
Use a temporary reservation/hold
- When a user selects a slot, place a short-lived hold in your system.
- This reduces race conditions where two people try to book the same time.
- Expire holds automatically if checkout is not completed.
-
Re-check before final commit
- Right before writing the booking, do one last conflict check.
- If there’s a conflict, fail gracefully and return alternative times.
Important details
- Normalize everything to one canonical timezone, usually UTC, and only convert for display.
- Respect event statuses:
busyshould block availabilityfreeshould not
- Handle recurring events, all-day events, tentative events, and meeting buffers carefully.
- Don’t assume external calendar data is immediately consistent; there can be sync delays.
- If you support multiple external calendars, merge all busy windows before calculating availability.
Best-practice architecture
- Calendar connector service: stores OAuth tokens and sync state
- Sync worker: fetches webhooks / polls changes
- Availability engine: computes open slots from busy windows + rules
- Booking transaction:
- acquire hold
- verify conflicts
- create booking
- optionally write back to external calendar
- release hold
Extra protection
- Make booking creation idempotent so retries don’t duplicate appointments.
- Use row-level locking / optimistic concurrency on the booking slot or host schedule if you’re in a multi-server environment.
- If you write events back to the external calendar, wait for confirmation and store the external event ID for future reconciliation.
If you want, I can also sketch a concrete database schema or a booking flow diagram for this.