Design a booking system
AirbnbSoftware Engineer · OnsiteLast updated
This question tests the ability to design a distributed reservation system that handles high concurrency, prevents double-booking, and ensures data consistency at scale.
Problem Statement
Design a booking system for a platform like Airbnb that allows guests to search for available listings and reserve them for specific dates. The system must support high-volume read requests (searching for listings) and high-integrity write requests (creating bookings).
Functional Requirements
- Users can search for available properties by location and date range.
- Users can create a booking for a specific property on available dates.
- A property cannot be double-booked for the same dates.
Non-Functional Requirements
- High availability for search queries.
- Strong consistency for booking transactions.
- Low latency for searching and booking.
- Scalability to handle millions of listings and thousands of concurrent requests.
Deliverables
- Define the core API endpoints for search and booking.
- Propose a data model (SQL vs. NoSQL) that balances search performance and transactional integrity.
- Explain the concurrency control strategy to prevent race conditions during the booking process.
- Describe the high-level architecture, including caching strategies and database sharding techniques.
Constraints
- Assume 1 million properties and 100 million daily searches.
- Users are distributed globally, requiring a system that is responsive regardless of geography.
Hints
Hint 1
Consider using an inverted index (like Elasticsearch) for the search component to handle complex spatial and date-based filtering efficiently.
Hint 2
For the booking transaction, evaluate whether row-level locking, optimistic concurrency control, or a distributed locking mechanism is most appropriate for your database choice.
Hint 3
Use a Read-Through or Write-Through cache (like Redis) for listing availability to reduce the load on the primary transactional database.
Follow-up questions
- How would you handle a scenario where a user reserves a property, but the payment service fails to process the transaction?
- If the database becomes a bottleneck during peak holiday season, what strategies would you use to shard your booking data?
- How would you implement a 'hold' feature that temporarily reserves a property for 10 minutes while a user completes their checkout?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.