Architecting a High-Throughput Hotel Reservation Platform
System DesignModel answerLast updated
Design a backend system handling 100k reads/sec and 10k booking attempts/sec with sub-200ms latency, preventing double-bookings under viral traffic spikes.
You're tasked with architecting the backend infrastructure for a hotel reservation platform that must handle extreme traffic patterns. The application serves a massive consumer base where properties can suddenly experience viral popularity, resulting in millions of concurrent users attempting to view and book the same location.
Core Capabilities
Users interact with the system to:
- Search properties by location, stay dates, and filtering criteria
- See current room availability and pricing for specific properties
- Submit reservation requests and receive immediate confirmation or denial
Functional Scope
- Property search supporting location, date ranges, and attribute filters
- Real-time display of remaining inventory and current rates for a given property and date span
- Reservation creation for selected properties, room categories, and date ranges
- Absolute guarantee: identical room-nights cannot be sold twice
- Basic cancellation support (high-level approach sufficient)
Performance & Scale Requirements
Concurrency:
- Peak load: approximately 100,000 availability queries per second
- Peak load: approximately 10,000 reservation attempts per second
Response Time:
- 99th percentile latency under 200ms for both availability checks and booking confirmations, measured client-side
Reliability:
- System must remain operational through individual node failures or complete availability zone outages
Consistency Model:
- Availability displays may show slightly outdated counts (eventual consistency acceptable)
- Booking commitments must be strictly correct (strong consistency required, zero double-bookings)
Message Delivery:
- Live availability updates pushed to clients can tolerate occasional dropped messages
- Booking requests and confirmations must never be lost
Traffic Distribution:
- Properties can become extremely popular with highly skewed traffic patterns
- Architecture must distribute load for viral properties across multiple nodes rather than concentrating on single endpoints
Protocol Considerations:
- Evaluate trade-offs between HTTP, persistent connections, and lightweight protocols
- Match protocol choice to reliability requirements and latency targets for each flow
Design Exercise
Your architecture should address:
-
Protocol selection and message reliability:
- When should you use persistent connections or lightweight protocols instead of standard HTTP?
- Which system flows can accept message loss, and which require guaranteed delivery?
-
Concurrent booking safety:
- How do you prevent multiple users from successfully reserving the final available room-night?
- What techniques (throttling, request batching, atomic operations, locking, queuing) apply here?
-
Load distribution for viral properties:
- How would you horizontally scale to handle a single extremely popular property?
- Compare approaches: partitioning by room identifiers versus partitioning by user identifiers
Your solution should include:
- Major system components and their responsibilities
- Data models for properties, room categories, inventory tracking, and reservations
- Complete request flows for availability lookup and booking confirmation
- Explanations of how your design achieves low latency, prevents double-bookings, and handles traffic hotspots
- Key trade-offs and rationale for your architectural decisions
You may assume any technology stack (relational/NoSQL databases, caching layers, message queues, etc.).
Hints
Hint 1
Start by identifying which operations require strong consistency versus eventual consistency—this drives your architecture choices.
Hint 2
Consider what happens when 5,000 users try to book 50 remaining rooms simultaneously. The system's primary job for viral properties is fast, cheap rejection.
Hint 3
Think about the unit of inventory: are you tracking individual physical rooms or fungible room-nights by category? This fundamentally changes your concurrency strategy.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Solution: High-Throughput Hotel Reservation Architecture
1. Establish Business Invariants First
Architecture follows from constraints. Define these before selecting technologies:
Inventory Model: Track availability by (property_id, room_category, date) tuples, not individual physical rooms. Customers reserve "a Suite for June 10-12", and the actual room assignment happens at check-in. This reduces the problem to maintaining counters where reserved + held ≤ capacity per tuple.
Atomicity: Multi-night stays are all-or-nothing. Partial reservations create operational chaos and must be prevented.
Consistency Requirements: Displayed counts are advisory. The booking commit is authoritative. Users understand that "5 rooms left" is approximate.
Failure Modes: Availability updates can be lossy; booking requests cannot. Design accordingly.
Capacity Reality: When a viral property receives 5,000 booking attempts per second for 40 remaining rooms, 99%+ will fail. Optimize for cheap, fast rejection rather than attempting to serialize thousands of transactions.
Clarifications to confirm:
- Does "confirmation" mean inventory hold or payment capture? (Assume: inventory secured with 10-minute hold; payment processes asynchronously)
- Do we own inventory or sync from external systems? (Assume: owned inventory)
2. Capacity Planning
| Metric | Estimate | Implication |
|---|---|---|
| Read queries | 100k/s globally; 30-50k/s for one viral property | Need multi-tier caching with request deduplication |
| Booking attempts | 10k/s total; 5k/s for hot property | Require admission control to protect database |
| Inventory records | 1M properties × 5 categories × 365 days = 1.8B rows (~200GB) | Shardable; hot working set fits in memory cache |
| Successful bookings | ~10% success rate = 1k/s = 86M/day | Partition by booking_id; archive historical data |
3. API Design
GET /properties/search?location=&checkin=&checkout=&filters=
→ paginated list of properties
GET /properties/{id}/inventory?checkin=&checkout=
→ [{category, available_count, price_per_night, data_version}]
WebSocket /updates/properties/{id}
→ streaming availability deltas (best-effort delivery)
POST /reservations
Body: {property_id, room_category, checkin, checkout, quantity}
Header: Idempotency-Key
→ {reservation_id, status: HELD|REJECTED, expires_at}
POST /reservations/{id}/finalize
Body: {payment_token}
→ {status: CONFIRMED|FAILED}
POST /reservations/{id}/cancel
→ {status: CANCELLED}
4. Data Schema
properties table: property_id (PK), location, coordinates, metadata — also indexed in Elasticsearch for search
room_categories table: property_id, category_id, total_rooms, base_price_per_night
inventory table: (property_id, category_id, date) composite PK, total_capacity, currently_held, confirmed_sold, optimistic_version
- Sharded by property_id so all nights for one booking reside on the same shard (local transactions)
- Storage: strongly consistent SQL (sharded PostgreSQL with synchronous replicas, or CockroachDB/Spanner)
reservations table: reservation_id (PK), idempotency_key (UNIQUE), user_id, property_id, category_id, checkin_date, checkout_date, room_count, status, hold_expiration, created_timestamp
event_outbox table: event_id, event_payload, processed_flag — transactionally written, then published to Kafka
5. System Architecture
Client ─ CDN ─ API Gateway ─┬─ Search Service ─ Elasticsearch
(auth, rate limits) ├─ Inventory Service ─ Redis cluster + local cache
├─ WebSocket Gateway ◄─ Kafka "inventory_updates"
└─ Reservation Service ─ Admission Control ─ Inventory DB
└─ Event Outbox → Kafka → downstream consumers
All services deploy as stateless pods across three availability zones. Inventory database uses quorum writes with synchronous cross-zone replication (no committed booking lost on zone failure). Kafka configured with acks=all and minimum in-sync replicas.
6. Availability Query Flow (Optimize for Latency)
Multi-Tier Caching:
- Search results and property pages served from CDN with 2-5 second TTLs
GET /inventoryrequests hit Inventory Service with:- In-process cache (1 second TTL) absorbing repeated queries
- Redis cluster as secondary cache
- Database read replica on cache miss
Request Coalescing: Using singleflight pattern, concurrent identical requests share a single backend fetch. A viral property receiving 50k queries/second generates only ~1 backend request per service pod per second.
Live Updates:
- Inventory changes trigger transactional outbox writes
- Background relay publishes to Kafka
inventory_updatestopic - WebSocket gateways consume and push to connected clients, including data version
- Dropped messages only cause temporary staleness until next push or client poll
- Clients poll every 10-30 seconds as fallback, reconciling on version gaps
Hotspot Mitigation: Property becomes a Kafka topic partition key; gateways subscribe and fan out to local WebSocket connections. Throttle to maximum one push per property per second, collapsing intermediate updates.
7. Booking Flow (Optimize for Correctness)
Phase 1: Gateway Filtering
- Apply per-user and per-IP rate limiting
- Enforce idempotency key requirement (safe client retries)
Phase 2: Admission Control
- Redis pre-check reads approximate
available_countfor the property/category - If zero, immediately return
REJECTED(< 10ms response, eliminates most viral traffic) - Otherwise, token bucket allows approximately
k × available_countrequests per time window (k ≈ 2) - Excess requests receive "sold out, please retry" — fast rejection without database load
- Critical: admission filter is never authoritative, only protective
Phase 3: Atomic Reservation Single-shard transaction on the property's database partition:
BEGIN;
-- Atomic conditional update with optimistic version check
UPDATE inventory
SET currently_held = currently_held + :qty,
optimistic_version = optimistic_version + 1
WHERE property_id = :pid
AND category_id = :cat
AND date >= :checkin
AND date < :checkout
AND (currently_held + confirmed_sold + :qty) <= total_capacity;
-- Verify all nights were updated (all-or-nothing)
-- If row_count != night_count, rollback and reject
INSERT INTO reservations
(reservation_id, idempotency_key, ..., status='HELD', hold_expiration=now()+10min);
INSERT INTO event_outbox (event_type='inventory_changed', ...);
COMMIT;
Row-level locks plus conditional WHERE clause make double-booking impossible. This is optimistic concurrency control without distributed locking, confined to single-shard transaction.
Return HELD status to user within 200ms budget.
Phase 4: Asynchronous Finalization
- Payment processing via Kafka consumer
- Success: transition
held → confirmed_sold, update booking toCONFIRMED - Failure or expiration: background sweeper releases held inventory
- Confirmation delivery via durable outbox with at-least-once semantics; consumers deduplicate by reservation_id
Hot-Row Contention Solution: Even with admission control, ~1,000 concurrent transactions create lock contention. Apply request batching:
- Route admitted requests for
(property, category)to single Kafka partition - Dedicated consumer drains batch every 10-20ms
- Allocate inventory in arrival order in-memory
- Commit entire batch in one transaction
- Return individual results to waiting requests
This converts 1,000 contended transactions into ~50-100 batched commits per second with zero lock waits. Latency remains under budget (batch accumulation + commit + response).
8. Sharding Strategy for Viral Properties
Primary Sharding: By property_id to keep multi-night bookings transactional.
Hot Property Options:
Option A: Room-Level Sharding
- Partition inventory within a property by room_category or even room ranges
- Pros: Spreads write load across database shards
- Cons: Multi-category bookings need distributed transactions or forced single-category; complicates inventory management
Option B: User-Based Request Distribution
- Hash user_id to route requests across application service pods
- Single property shard handles writes, but admission/batching distributes connection load
- Pros: Maintains transactional simplicity, spreads connection/CPU load
- Cons: Database shard remains bottleneck for commits
Recommended: Option B with aggressive admission control and request batching. Database shard can handle 1-2k commits/second; batching reduces contention dramatically. Reserve room-level sharding for properties with genuine inventory exceeding single-shard capacity (mega-resorts with 1000+ rooms).
9. Protocol Selection
Availability Queries: Standard HTTP/2 with connection pooling. Caching eliminates most backend calls; marginal protocol overhead is negligible.
Live Updates: WebSocket connections for properties users are actively viewing. Stateful but acceptable for temporary subscriptions. UDP inappropriate (needs connection state and basic ordering). HTTP/2 Server-Sent Events viable alternative.
Booking Requests: Standard HTTPS POST. Requires reliability, authentication, and idempotency — exactly what HTTP provides. Latency budget (200ms) is comfortable for request-response over HTTP.
10. Key Trade-offs
| Decision | Trade-off | Rationale |
|---|---|---|
| Eventual consistency for availability display | Accuracy vs latency/scale | Users tolerate "approximately 5 left"; cannot tolerate 200ms+ queries hitting database |
| Admission control before database | Some false rejections vs database protection | Occasional "sold out" on available inventory is preferable to database overload and timeout cascades |
| Request batching | Individual request latency vs throughput | 10-20ms batching keeps p99 under 200ms while preventing lock contention |
| Sharding by property | Hot property limits vs transactional simplicity | Single mega-property bottleneck is rare; maintaining ACID semantics is critical |
| WebSocket for updates | Stateful connections vs push latency | Users viewing property details are temporary, bounded population; push updates are 10x faster than polling |
11. Disaster Recovery
- Cross-zone synchronous replication: zero booking loss on zone failure
- Kafka replication: at-least-once delivery of payment events
- Idempotency keys: safe retry on client or gateway timeout
- Read replica promotion: availability queries continue during primary database recovery
This architecture handles 100k reads/second and 10k booking attempts/second while maintaining sub-200ms latency and zero double-bookings through layered admission control, optimistic concurrency, and strategic use of eventual consistency where business requirements permit.