Hello! Welcome to your lesson on designing a rental booking system.
In our last session, we designed a food delivery service like DoorDash. We focused on the complex, real-time logistics of a three-sided marketplace, using geospatial indexing for proximity searches and an ML-powered optimization engine for efficient dispatch.
Today, we shift our focus to another giant of the sharing economy: Airbnb. Our learning outcome is to design a hotel/rental booking system, focusing on search, availability, and concurrency.
While both DoorDash and Airbnb are marketplaces, they present fundamentally different engineering challenges. DoorDash optimizes for short-duration logistics measured in minutes. Airbnb, on the other hand, is about managing long-term, unique inventory (homes) over days, weeks, and months. This brings the critical problems of complex search, calendar management, and transactional integrity to the forefront.
1. Requirements for a Two-Sided Marketplace
Before diving into the architecture, it's crucial to understand the system's core principles and requirements. Airbnb is a classic two-sided marketplace that must serve both guests and hosts.
Core Principles of Designing a Marketplace System
To frame our thinking, let's start with this guide that outlines the core principles of designing a marketplace system like Airbnb. It will help us anchor our technical decisions in the business reality of the platform.
Read the section 'Core Principles of Designing a Marketplace System'. Pay attention to the concepts of 'Two-Sided Network Effects', 'Trust and Safety', and especially 'Real-Time Availability Management'. These principles directly inform our non-functional requirements.
Building on these principles, let's define our system's requirements.
Functional Requirements:
- Guests:
- Search for listings based on location, date range, number of guests, and other filters (amenities, price).
- View detailed information about a listing, including photos, reviews, and its availability calendar.
- Book a listing for specific dates.
- View and manage their upcoming and past reservations.
- Hosts:
- Create, update, and manage their listings (details, photos, price).
- Manage their listing's availability calendar by blocking or unblocking dates.
- View and manage bookings for their properties.
Non-Functional Requirements:
- High Availability: The system must be highly available, as downtime means direct revenue loss.
- Consistency: Booking is a financial transaction. We need strong consistency to prevent double-bookings.
- Low Latency: Search and page loads must be fast to ensure a good user experience.
- Scalability: The system must handle millions of users and listings globally.
A key trade-off, as dictated by the CAP theorem, emerges here. The Search functionality can favor availability (AP), tolerating slight delays in data replication. However, the Booking functionality must favor consistency (CP) to maintain transactional integrity.
2. High-Level Architecture
A microservices architecture is a natural fit for this system, allowing us to scale and develop services independently.

The core services we will focus on are:
- Search Service: Responsible for finding available listings based on various criteria.
- Booking Service: Handles the entire reservation workflow, from initiation to confirmation.
- Listing Service: The source of truth for all property data and availability calendars.
- Payment Service: Integrates with third-party processors.
- Notification Service: Sends confirmations and updates to users.
3. Deep Dive: Search and Discovery
Airbnb's search is more complex than a simple keyword search. It must efficiently filter millions of listings by location, price, amenities, and, most importantly, availability for a given date range.
The Challenge of Combined Search Criteria
Let's break down the search query: "Find me a 2-bedroom apartment in San Francisco, with a pool, for July 10-15". This query has three distinct parts:
- Text/Attribute Search: "2-bedroom apartment", "pool".
- Geospatial Search: "in San Francisco".
- Date Range Search: "for July 10-15".
Querying a relational database with JOINs across multiple tables for listings, amenities, and availability calendars for millions of records would be far too slow. The solution is to denormalize this data into a dedicated search engine.
✅ System Design 5: Design Hotel Booking App like AirBnb / Booking.com | Proximity | HLD | LLD
This video provides an excellent deep dive into designing the search service, comparing different database schemas and geospatial search techniques.
Watch from 22:54 to 32:42 and then 33:29 to 45:24. Focus on these key points: Schema Design: The two approaches for storing availability data (daily records vs. date ranges) and their trade-offs in storage vs. query/update complexity. Proximity Search: The comparison between ElasticSearch, Quad Trees, and GeoHash. Note the justification for choosing ElasticSearch because it supports both textual and location search out-of-the-box. Optimized Search Flow: The two-phase search strategy where ElasticSearch first finds candidate listings, and a subsequent step fetches detailed availability.
Let's summarize and build upon that excellent analysis.
Architecture for Search:
- Data Ingestion: We use a Change Data Capture (CDC) pipeline (like Debezium) to stream updates from our primary databases (e.g., PostgreSQL containing listings, amenities, and availability tables) to a consumer service.
- Denormalization: This consumer service denormalizes the data, creating a single JSON document for each listing. This document includes all searchable fields:
listing_id,title,location(as a geo-point),amenities(as an array of tags),price, etc. - Indexing: The denormalized documents are indexed in ElasticSearch. ElasticSearch is ideal because it excels at combining full-text search, geospatial queries, and structured data filtering in a single query.
- Handling Availability: How do we index availability in ElasticSearch for efficient date range queries?
- Approach A (Booked Dates): Index an array of all booked dates for each listing. The query would then filter for listings
WHERE date NOT IN [query_start_date ... query_end_date]. This can be complex and inefficient for long date ranges. - Approach B (Nested Date Ranges): ElasticSearch supports
date_rangefields. We can store an array of booked date ranges. The query would then check for any overlaps with the desired booking period. This is a powerful and efficient approach.
- Approach A (Booked Dates): Index an array of all booked dates for each listing. The query would then filter for listings

4. Deep Dive: Booking and Concurrency Control
This is the most critical part of the design. A failure here could lead to double-bookings, resulting in significant financial and reputational damage. The core challenge is a classic race condition: two users try to book the same property for the same overlapping dates simultaneously.
We need a mechanism to ensure atomicity across the booking process: check availability, hold the dates, process payment, and confirm the booking.
Concurrency issues in hotel reservation system
The ByteByteGo article provides one of the best and most detailed explanations of handling concurrency issues in a reservation system. It systematically covers different solutions and their trade-offs.
Please read the entire 'Concurrency issues' section. This is the most important reading for this lesson. Focus on understanding: Idempotency: How using a unique key (like reservation_id) prevents the same user from creating duplicate bookings by double-clicking. The Race Condition: The detailed example of how two transactions can both read the available inventory and incorrectly create a double-booking. Concurrency Solutions: The pros and cons of Pessimistic Locking, Optimistic Locking, and Database Constraints. Pay close attention to why Optimistic Locking is a strong candidate.
While optimistic locking is a powerful database-level pattern, another very common and practical approach for web-scale systems is to use a distributed lock.
✅ System Design 5: Design Hotel Booking App like AirBnb / Booking.com | Proximity | HLD | LLD
This video explains a practical way to handle concurrency using a temporary lock, which is a common pattern for 'holding' an item during checkout.
Watch the segment from 58:05 to 01:02:35. The key idea here is using a Redis lock with a TTL (Time-To-Live). When a user starts the booking process, we acquire a lock on that specific listing for a short period (e.g., 5-10 minutes). This prevents other users from starting the booking process for the same dates.
The Transactional Booking Flow (Saga Pattern)
A complete booking involves multiple services and cannot be wrapped in a single database transaction. This is a perfect use case for the Saga pattern, which coordinates a series of local transactions across microservices. If any step fails, compensating transactions are executed to undo the previous steps.
Let's orchestrate this with an event-driven architecture.
- Initiate Booking: A guest clicks "Reserve". A request hits the
Booking Service. - Acquire Lock: The
Booking Serviceattempts to acquire a distributed lock in Redis for the unique combination oflisting_idand the requested date range. For example,lock:listing_456:2024-08-20:2024-08-25. The lock is set with a TTL (e.g., 10 minutes).- If the lock is acquired, proceed.
- If the lock is already held, the system immediately informs the guest that the property is currently being booked by someone else.
- Process Payment: The
Booking Servicecalls thePayment Serviceto authorize the payment. - Confirm & Publish Event: If payment is successful, the
Booking Servicedoes two things:- Persists the reservation details to its own database (which should be a relational DB like PostgreSQL for ACID guarantees).
- Publishes a
BookingConfirmedevent to a Kafka topic.
- Update Availability (Asynchronously): The
Listing Serviceconsumes theBookingConfirmedevent. It updates its primary database to mark the dates as unavailable. This change is then propagated to ElasticSearch via the CDC pipeline, ensuring search results are eventually consistent. - Send Notifications: The
Notification Servicealso consumes theBookingConfirmedevent and sends confirmation emails/push notifications to the host and guest. - Release Lock: The
Booking Serviceexplicitly deletes the Redis lock. If this step fails or the service crashes, the lock's TTL acts as a safety net, automatically releasing the dates after the timeout.
This Saga pattern, combined with a distributed lock, provides a robust, scalable, and fault-tolerant solution to the concurrency problem.
Conclusion
Designing a rental booking system like Airbnb requires a deep focus on search, inventory management, and transactional integrity. Unlike real-time logistics, the core challenges here revolve around managing a large, static inventory with complex search filters and ensuring that concurrent booking requests are handled without conflict.
Key Takeaways:
- Search Strategy: A combination of denormalization into a specialized search engine like ElasticSearch and a multi-phase query strategy is essential for handling complex filters (geo, text, date) at scale.
- Availability Modeling: Representing availability calendars requires a trade-off. A common, effective model is to store an entry per listing per day in your primary DB, which can then be indexed for efficient querying.
- Concurrency is Critical: Preventing double-bookings is a primary concern. A robust solution combines a distributed lock (e.g., Redis with TTL) to temporarily hold inventory during the checkout process with a transactional Saga pattern to coordinate the multi-step booking flow across microservices.
- Event-Driven Architecture: Using a message broker like Kafka is key to orchestrating the Saga, decoupling services, and ensuring the system is resilient to partial failures.
Preview of the Next Lesson:
So far, we have focused on designing the what and how of our systems. But a Staff-level engineer is also responsible for a system's operational health. In our next lesson, we will move into the "Staff-Level System Design Depth" module and address a crucial aspect of operating these complex systems: articulating an observability strategy, covering metrics, logging, and tracing. We'll discuss how you would monitor the health and performance of the Airbnb system we just designed.