Prevent Double Booking When Two Guests Reserve the Same Nights

Last updated: November 29, 2026

Quick Overview

Two guests click Reserve on the same listing for overlapping nights within milliseconds, and requests land on different app servers. Explain how you guarantee at most one reservation wins, covering in-process locking, database constraints, and transaction isolation, and sketch the core logic in code.

Airbnb
Software Engineering Fundamentals
Software Engineer
Airbnb
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Two guests click Reserve on the same listing for overlapping nights within milliseconds, and requests land on different app servers. Explain how you guarantee at most one reservation wins, covering in-process locking, database constraints, and transaction isolation, and sketch the core logic in code.

Double bookings are among the worst trust failures Airbnb can have, because a guest may arrive to find someone else in the home. Interviewers use this to see whether you understand that check-then-act races need atomicity at the database, and that an application lock alone is not enough across many servers.

What the Interviewer Expects
  • Name the check-then-act race precisely
  • Explain why a per-process lock does not work across servers
  • Propose a database-enforced invariant such as a unique (listing, night) row or an exclusion constraint
  • Discuss isolation levels and when SELECT FOR UPDATE is needed
  • Cover retries, deadlock ordering, and user-facing behavior for the loser
Key Topics to Cover
race conditions
locking
unique constraints
transaction isolation
databases
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Would you use optimistic or pessimistic concurrency here, and why?
  • How does a pending hold during payment authorization fit in?
  • How do you handle a listing synced to an external calendar that can also take bookings?
  • How would you test that the fix actually works?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Invariant: for any listing and night, at most one confirmed or held reservation. Many stateless app servers, one primary database per shard. The losing request must fail fast with a clear 'dates no lo...

High-Level Design

The bug is check-then-act: both requests read 'nights free', then both insert. Fixes by layer:

  • Database invariant (the real fix): a listing_nights table with a unique key on (listing_id, night...

Submit Your Answer
Markdown supported