Bird
Raised Fist0

Design a Hotel Booking System - Inventory, Reservation, Double Booking Prevention

HLDhardInterview freq: high
Choose your preparation mode4 modes available
🎯
Design a Hotel Booking System - Inventory, Reservation, Double Booking Prevention
45 min · senior
senior

You are designing a hotel booking system for a startup with 50 million daily active users. The system must handle real-time inventory updates, support concurrent reservations, and prevent double bookings of rooms. The system should provide a seamless user experience with P99 latency under 200ms. Data must be encrypted at rest and in transit. The system should also support offline booking capabilities for partner agents with eventual sync.

  • P99 request latency under 200ms for booking and inventory queries
  • Data encryption at rest and in transit (TLS + AES-256)
  • Support for offline booking by partner agents with eventual synchronization
  • Prevent double booking of the same room for overlapping dates
  • Handle 50M DAU with peak booking rates of 100K requests per second
📋
Guided Steps
1/5
Step 1
Inventory Data Modeling and Storage
How would you model and store hotel room inventory to support fast availability queries and updates at scale?
💡 Hint
Consider a database optimized for range queries on date intervals and high write throughput.
Use Apache Cassandra with a composite partition key of hotel_id and room_type, clustering by date to enable efficient range scans for availability over date ranges.
Mid-level: Names Cassandra for scalability. Senior: Explains composite partition key design to support range queries on dates and why relational DBs like MySQL would bottleneck at 100K writes/sec.
⚠️Common Wrong Answer
Using a relational database with row-level locking for inventory updates, causing write contention and poor scalability under high booking rates.
Step 2
Reservation Creation and Double Booking Prevention
How do you ensure that two users cannot book the same room for overlapping dates concurrently?
💡 Hint
Think about distributed locking or atomic conditional writes that scale horizontally.
Leverage Cassandra lightweight transactions (LWT) with Paxos protocol for conditional inserts on reservation records keyed by room_id and date range to prevent double booking.
Mid-level: Mentions distributed locking or transactions. Senior: Details Cassandra LWT usage, trade-offs on latency, and why Redis distributed locks fail due to lack of strong consistency guarantees.
⚠️Common Wrong Answer
Using Redis distributed locks without strong consistency, leading to race conditions and double bookings under concurrent requests.
Step 3
Handling Offline Booking and Eventual Sync
How would you design the system to support offline booking by partner agents and synchronize reservations later without conflicts?
💡 Hint
Consider event sourcing or conflict-free replicated data types (CRDTs) for eventual consistency.
Implement an event sourcing pattern using Apache Kafka to log offline booking events, with a reconciliation service that applies conflict resolution rules during sync.
Mid-level: Suggests queue-based sync. Senior: Explains Kafka's partitioning for ordering, idempotent consumers, and conflict resolution strategies to handle offline merges.
⚠️Common Wrong Answer
Batch syncing without ordering guarantees, causing inconsistent inventory states and potential double bookings.
Step 4
API Design for Booking Workflow
Design three core REST API endpoints for querying inventory, creating reservations, and confirming bookings. What are their inputs, outputs, and error handling strategies?
💡 Hint
Think about idempotency, optimistic concurrency, and clear client-server contract.
Define GET /inventory with date range and filters, POST /reservations with idempotency keys and conditional writes, and POST /reservations/{id}/confirm with status updates and notifications via Webhooks.
Mid-level: Lists endpoints and basic request/response. Senior: Details idempotency keys, error codes for conflicts, and asynchronous confirmation with callbacks.
⚠️Common Wrong Answer
Designing non-idempotent POST endpoints causing duplicate bookings on retries.
Step 5
Security and Encryption
How do you ensure data encryption at rest and in transit for sensitive booking data?
💡 Hint
Consider TLS for transport and encryption options supported by your storage technology.
Use TLS 1.3 for all client-server and inter-service communication, and enable Cassandra Transparent Data Encryption (TDE) with AES-256 for data at rest.
Mid-level: Mentions TLS and encryption. Senior: Explains TLS version choice, key management, and Cassandra TDE integration with hardware security modules (HSM).
⚠️Common Wrong Answer
Relying only on network-level encryption without encrypting data at rest, risking data exposure on disk.
🔌
API Design Challenge
Sketch 3 core API endpoints for the hotel booking system focusing on inventory query, reservation creation, and reservation confirmation.
  • How does the client query available rooms for given dates and filters?
  • How does the client create a reservation and ensure atomicity?
  • How does the system confirm or cancel a reservation and notify the client?
📊
Scoring Rubric
▼ Show
Must Have - 60%
  • Use of Cassandra with appropriate data modeling for inventory and reservations
  • Mechanism to prevent double booking using strong consistency (Cassandra LWT)
  • API design including idempotency and error handling for booking workflow
  • Encryption in transit and at rest
Good to Have - 30%
  • Offline booking support with event sourcing via Kafka
  • Conflict resolution strategy during offline sync
  • Asynchronous notification system for booking confirmation
Bonus - 10%
  • Detailed explanation of partition key design trade-offs
  • Discussion of failure modes in distributed locking and reconciliation
Using relational databases with row-level locking causing write bottlenecks under 100K RPS, leading to poor scalability and high latency
Relying on Redis distributed locks without strong consistency leading to race conditions and double bookings under concurrent requests
Batch syncing offline bookings without ordering guarantees causing inconsistent inventory states and potential double bookings
Non-idempotent API endpoints causing duplicate bookings on client retries, resulting in data inconsistency and user confusion
Encrypting only in transit but not at rest exposing sensitive data on disk to unauthorized access
Ignoring reconciliation and conflict resolution for offline bookings causing data corruption and inconsistent system state
✅
Model Answer
▼ Reveal

The system uses Apache Cassandra for scalable inventory and reservation storage with LWT to prevent double bookings. Offline bookings are handled via Kafka event sourcing with a reconciliation service to ensure eventual consistency. The API design includes idempotency keys to handle retries safely, and TLS 1.3 plus Cassandra TDE with AES-256 ensure encryption in transit and at rest.

  • Choosing Apache Cassandra for its high write throughput and support for range queries via composite partition keys
  • Using Cassandra Lightweight Transactions (LWT) with Paxos protocol to prevent double bookings by ensuring atomic conditional inserts
  • Implementing event sourcing with Apache Kafka to support offline bookings and eventual synchronization with conflict resolution
  • Designing REST APIs with idempotency keys to handle retries and avoid duplicate bookings
  • Employing TLS 1.3 for secure communication and Cassandra TDE with AES-256 for encryption at rest to protect sensitive data
  • Using a reconciliation service to consume Kafka events and apply conflict resolution rules during offline sync
  • Providing asynchronous notifications via Webhooks to inform clients about reservation confirmations and status changes
  • Apache Cassandra with composite partition key (hotel_id, room_type) and clustering by date for scalable inventory queries
  • Cassandra Lightweight Transactions (LWT) using Paxos for atomic reservation creation preventing double bookings
  • Apache Kafka event sourcing for offline booking event logging and eventual consistency reconciliation
  • REST API design with idempotency keys on POST /reservations to handle retries safely
  • TLS 1.3 for all network communication ensuring encryption in transit
  • Cassandra Transparent Data Encryption (TDE) with AES-256 for encryption at rest
  • Reconciliation service consuming Kafka events to resolve conflicts during offline sync
  • Webhook-based asynchronous notification system for reservation confirmation and status updates

Practice

(1/5)
1. In the log aggregation pipeline, at Step 4 the Log Processor reads from Kafka and enriches logs with metadata. What happens if the enrichment service is temporarily unavailable at this step?
easy
A. The Log Processor buffers logs locally and retries enrichment until successful
B. The Log Processor skips enrichment and forwards raw logs downstream
C. The Log Processor commits Kafka offsets immediately and drops logs
D. The Log Processor crashes and restarts without processing logs

Solution

  1. Step 1: Trace Log Processor behavior at Step 4

    It reads logs from Kafka and enriches them before forwarding.
  2. Step 2: Understand failure handling

    If enrichment service is down, buffering and retrying prevents data loss and ensures enrichment.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Buffer and retry enrichment -> no data loss or offset commit [check]
Hint: Buffer and retry enrichment to avoid data loss [check]
Common Mistakes:
2. To support personalized course recommendations at scale, should the system use a batch offline ML pipeline or a real-time streaming recommendation engine? Consider latency and update frequency constraints.
medium
A. Use batch offline ML pipeline for real-time personalized recommendations
B. Use real-time streaming engine with complex models requiring heavy computation
C. Use real-time streaming engine for low-latency but less accurate recommendations
D. Use batch offline ML pipeline for periodic recommendations with high accuracy

Solution

  1. Step 1: Analyze latency and update frequency constraints

    Real-time streaming (Options C and D) offers low latency but may sacrifice model complexity or accuracy.
  2. Step 2: Evaluate batch offline pipeline suitability

    Batch offline ML (Use batch offline ML pipeline for periodic recommendations with high accuracy) provides higher accuracy with periodic updates, suitable when real-time freshness is not critical.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Batch offline pipeline balances accuracy and periodic updates [check]
Hint: Batch ML for accuracy, streaming for latency trade-off [OK]
Common Mistakes:
3. If the health monitoring component of the GSLB fails silently, what is the most likely failure observed by end users?
medium
A. Users are routed to unhealthy data centers causing request failures or timeouts
B. Traffic is evenly distributed regardless of data center health, causing overload
C. DNS queries fail to resolve, causing complete service outage
D. Users experience increased latency due to rerouting through backup data centers

Solution

  1. Step 1: Understand health monitor role

    The health monitor informs GSLB which data centers are healthy; without it, GSLB cannot avoid unhealthy endpoints.
  2. Step 2: Analyze failure impact

    Without health info, GSLB routes users to unhealthy data centers causing failures (Users are routed to unhealthy data centers causing request failures or timeouts). Increased latency (Users experience increased latency due to rerouting through backup data centers) or DNS failures (DNS queries fail to resolve, causing complete service outage) are indirect or unlikely. Even traffic distribution (Traffic is evenly distributed regardless of data center health, causing overload) ignores health but is less precise than routing to unhealthy nodes.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Silent health monitor failure -> routing to unhealthy data centers [check]
Hint: No health data -> users sent to unhealthy data centers [check]
Common Mistakes:
4. At 10x scale, which component in a Kafka-like distributed message queue is most likely to fail first, and why?
hard
A. The Kafka brokers, because partition leaders become overloaded with write and replication traffic
B. The consumer clients, because they cannot keep up with increased message consumption rates
C. The ZooKeeper ensemble, due to coordination overhead and leader election delays under heavy load
D. The network switches, due to increased packet loss under high throughput

Solution

  1. Step 1: Identify bottlenecks at 10x scale

    Network switches (A) scale with hardware upgrades; ZooKeeper (C) handles coordination but is lightweight compared to brokers; consumers (D) can be scaled horizontally.
  2. Step 2: Kafka broker partition leader overload

    Partition leaders handle all writes and replication for their partitions; at 10x scale, leaders become hotspots causing CPU, disk, and network saturation, leading to failures.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Partition leaders overloaded -> broker failure first at scale [check]
Hint: Partition leaders handle all writes -> overload first at scale [check]
Common Mistakes:
5. At 10x scale, which component in a durable messaging system fails first and why?
hard
A. The database crashes due to increased write volume
B. Kafka brokers fail because partition leaders become overloaded with replication and disk I/O
C. Delivery workers fail because they cannot keep up with message fan-out
D. Chat servers fail because WebSocket connections are stateful and cannot be resharded

Solution

  1. Step 1: Identify bottlenecks at 10x scale

    Databases (A) can be scaled with sharding; delivery workers (C) can be horizontally scaled; chat servers (D) are stateful but not the first to fail.
  2. Step 2: Analyze Kafka broker load

    Kafka brokers handle replication and disk I/O per partition leader; at 10x scale, leaders become overloaded causing broker failures first.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Kafka partition leaders overloaded with replication cause first failure at scale [check]
Hint: Kafka partition leaders hit replication I/O bottleneck first at scale [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard