Design a High-Concurrency Reservation Platform
System DesignModel answerLast updated
Build a scalable property reservation system that handles millions of searches and prevents double-booking through strong consistency guarantees.
You're tasked with architecting a reservation platform for short-term property rentals. The system must allow guests to discover available properties and complete reservations while maintaining data integrity under heavy concurrent load.
Core Requirements
What users need to do:
- Search for properties matching location criteria and specific date ranges
- Reserve a property for chosen dates
- System guarantees: no property can be reserved twice for overlapping dates
Performance and scale expectations:
- Search operations must remain fast and available even under peak load
- Reservation operations require absolute correctness—no race conditions allowed
- Response times must stay low for both discovery and transaction flows
- System must accommodate millions of properties and handle thousands of simultaneous requests
What You Should Deliver
- Core API design for discovery and reservation flows
- Data storage strategy—justify your choice between relational and non-relational approaches, considering both query patterns and transactional needs
- Detailed concurrency mechanism to eliminate double-booking scenarios
- Overall system architecture covering caching approaches and horizontal scaling techniques
Scale Parameters
- Property inventory: 1 million active listings
- Daily search volume: 100 million queries
- Users span multiple continents and expect consistent performance
Hints
Hint 1
Consider the read-to-write ratio—how does that shape your architecture?
Hint 2
Think about what level of consistency each operation truly needs
Hint 3
A calendar made of individual records can simplify locking logic
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: High-Concurrency Reservation Platform
Understanding Scale and Consistency Requirements
Start by establishing the operational profile. The numbers drive every subsequent decision.
Volume estimates:
- 1M properties in inventory
- 100M searches daily → approximately 1,200 queries/second average, likely 10,000 QPS during peak hours
- Estimated 1M reservation attempts daily → roughly 12/second average, 200/second at peak
- Read-to-write ratio: approximately 100:1 to 1000:1
Calendar storage calculation: With a 2-year booking window, you have 1M properties × 730 days = 730M date records. At roughly 50 bytes per record, that's around 40GB—easily manageable with partitioning.
Critical insight: Search can tolerate slight staleness (eventual consistency), but reservations demand immediate consistency. This split—relaxed for reads, strict for writes—should guide every component choice.
API Design
GET /v1/properties/search
?location=lat,lng,radius&checkin=2025-07-01&checkout=2025-07-05
&capacity=2&max_price=300&page_token=…
Response: {
properties: [{id, name, total_cost, rating, image}],
next_page_token
}
POST /v1/reservations
Headers: Idempotency-Token: <uuid>
Body: {property_id, checkin, checkout, guests}
Response 201: {reservation_id, state: "PENDING", expires_at}
Response 409: {error: "DATES_UNAVAILABLE", suggested_alternatives: […]}
POST /v1/reservations/{id}/complete
Body: {payment_token}
Response 200: {state: "CONFIRMED"}
Response 402: {error: "PAYMENT_DECLINED"}
Dates use half-open intervals: [checkin, checkout), so checkout day is available for the next guest. The idempotency token makes retries safe without creating duplicate reservations.
Data Model: Relational Core + Search Index
Use a relational database (PostgreSQL or MySQL) as the authoritative source. Reservations require ACID transactions and constraint enforcement.
properties (
id PRIMARY KEY,
owner_id,
location GEOGRAPHY,
city,
max_capacity,
nightly_rate,
...
)
availability_calendar (
property_id,
date DATE,
state ENUM('OPEN', 'HELD', 'RESERVED', 'BLOCKED'),
reservation_id NULLABLE,
hold_until NULLABLE,
rate DECIMAL,
PRIMARY KEY (property_id, date)
)
reservations (
id PRIMARY KEY,
property_id,
guest_id,
checkin DATE,
checkout DATE,
state ENUM('PENDING', 'CONFIRMED', 'CANCELLED', 'EXPIRED'),
idempotency_token UNIQUE,
total_amount,
created_at
)
Why individual date rows? This structure converts "no overlap" checking into a simple, lockable condition: "every date must be OPEN." It also naturally handles per-night pricing and owner-initiated blocks. Alternatively, PostgreSQL's exclusion constraints with daterange types work elegantly but limit portability and complicate sharding.
Search infrastructure uses Elasticsearch. Each document contains geolocation, amenities, pricing, and rating. Elasticsearch doesn't store the authoritative availability data.
Architecture Overview
Clients → CDN/Load Balancer → API Layer (authentication, rate limiting)
│
├─ Search Service
│ ├─► Elasticsearch cluster (geo queries, regional replicas)
│ └─► Redis availability cache (date bitmaps, replicated per region)
│
└─ Reservation Service
└─► Reservation DB (sharded by property_id)
│
└─ Change stream → Message Queue
├─► Cache updater
├─► Search index sync
└─► Payment processor, notifications, analytics
Search flow:
- Elasticsearch executes geo-bounded query with filters (capacity, price, amenities), returning top 500–1000 candidates
- Search Service checks availability for each candidate against Redis bitmaps (each property uses ~46 bytes/year for a 365-bit vector—entire dataset fits in 50MB and replicates cheaply)
- Available results get ranked and paginated
Caching strategy:
- Availability bitmaps in Redis: updated immediately after reservation commits, with change-data-capture as a reconciliation backstop. Minor staleness acceptable since reservation flow revalidates.
- Property metadata: long-TTL read-through cache. Static assets via CDN.
- Popular queries: cache by
(geo_tile, dates, guests)for 30–60 seconds.
Global distribution: Search components (Elasticsearch, Redis, stateless services) deploy in every region for local reads. Reservation writes route to the single primary shard owning that property. The extra 100–200ms latency on writes is acceptable given write rarity.
Preventing Double-Booking: The Critical Detail
Since all dates for a property live on one shard, a database transaction provides sufficient coordination—no distributed locks needed.
Preferred approach: Atomic conditional update
BEGIN TRANSACTION;
UPDATE availability_calendar
SET state = 'HELD',
reservation_id = :new_reservation_id,
hold_until = NOW() + INTERVAL '10 minutes'
WHERE property_id = :property_id
AND date >= :checkin
AND date < :checkout
AND (state = 'OPEN' OR (state = 'HELD' AND hold_until < NOW()));
-- Verify updated row count matches expected nights
-- If mismatch: ROLLBACK and return 409
INSERT INTO reservations (...) VALUES (...);
COMMIT;
Row-level locks serialize concurrent transactions. The second transaction reevaluates the WHERE clause after the first commits, finds fewer matching rows, and aborts cleanly. No separate read-lock-check pattern means no race window.
Alternative: Explicit locking
BEGIN TRANSACTION;
SELECT * FROM availability_calendar
WHERE property_id = :property_id
AND date >= :checkin AND date < :checkout
ORDER BY date
FOR UPDATE;
-- Verify all rows show state='OPEN'
-- Update rows and insert reservation
COMMIT;
Ordering the SELECT avoids deadlocks. Both approaches work; the UPDATE-based method requires fewer round-trips.
Why not optimistic concurrency (version columns)? It works but requires checking N versions for N nights. Under contention, failed retries waste cycles. Since only one reservation succeeds per time slot, contention remains naturally low and pessimistic locking scales well.
Key Tradeoffs
- Stale search vs. failed checkout: Users occasionally see properties already taken. Better than blocking search on write-path consistency. Clear error messages and alternative suggestions mitigate frustration.
- Per-night granularity vs. range storage: More rows, but simpler locking and precise pricing control.
- Single-writer per property vs. multi-region writes: Avoids conflict resolution complexity at the cost of cross-region latency for some writes.
- Immediate confirmation vs. approval workflow: Request-to-book adds a PENDING_APPROVAL state but reuses the same holding mechanism.
What Strong Answers Include
- Explicit recognition that search and reservations need different consistency models
- Concrete concurrency mechanism shown in SQL, not abstract "use locks"
- Specific sharding strategy with rationale
- Quantitative justification for caching choices
- Discussion of failure modes (expired holds, payment failures, cache inconsistency) and recovery paths
- Awareness that geographic distribution creates latency/consistency tradeoffs
Common mistakes: treating double-booking as an application-layer retry problem, using distributed locks unnecessarily, proposing NoSQL without explaining how to enforce uniqueness constraints, ignoring the read-dominated workload in the architecture.