Design a Short-Term Rental Platform at Scale
System DesignModel answerLast updated
Design the backend for a global property rental marketplace handling millions of listings, concurrent bookings, and sub-200ms search with zero overbooking.
Context
You're building the backend for a property rental platform that operates globally. Hosts list their homes, guests search by location and dates, and the platform must guarantee no two guests are ever confirmed for the same property on the same night.
Functional Requirements
- Search: Guests can find available listings by geographic area (lat/long + radius), travel dates, and number of guests.
- Booking: Guests can reserve a listing for a date range. The system must prevent double bookings under any level of concurrency.
- Listing management: Hosts can create and update listings, set nightly prices, and block or open dates on their availability calendar.
Non-Functional Requirements
- High availability: Both the search and booking flows must tolerate failures without going down.
- Strong consistency on writes: Booking confirmations must be strictly correct — overbooking is never acceptable.
- Search latency: p99 search results must return within 200 ms.
What Your Answer Should Cover
- Data model: Schemas for listings, bookings, and availability calendars, with rationale for your choices.
- API design: Core endpoints for search, listing management, and the booking flow.
- System architecture: The major components — search index, booking service, databases, caching layer — and how they connect.
- Read vs. write strategy: How you separate the high-throughput read path (search) from the high-consistency write path (booking).
- Scaling: How the system handles geographic traffic spikes and peak booking periods (holidays, sale windows).
Take 35–40 minutes. Start by stating your assumptions about scale, then walk through each area. Be prepared to go deeper on the concurrency control mechanism and the search latency budget.
Hints
Hint 1
Search and booking have opposite requirements — search tolerates stale data, booking tolerates almost no concurrency error. Design them as separate paths from the start rather than sharing a single database read/write model.
Hint 2
Think about where your shard or partition key lands. If a listing, its calendar, and its bookings all live on the same shard, your booking transaction stays single-shard ACID with no distributed coordination needed.
Hint 3
For availability filtering in search, the index will always lag the booking database by a few seconds. That's fine — just make sure the booking path re-validates before confirming. Explain this explicitly so the interviewer knows it's intentional.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Step 1: Clarify Scale Before Drawing Anything
State assumptions out loud so the interviewer can correct them early.
- Listings: ~7M active, ~20 KB of metadata each → ~140 GB in the database; photos live in object storage behind a CDN.
- Search traffic: ~100M searches/day → ~1.2K avg QPS, plan for 10–20K QPS at peak due to seasonality.
- Booking traffic: ~1M bookings/day → ~12/s average, a few hundred/s at peak; checkout attempts run ~10× completed bookings.
- Calendar data: 7M listings × 365 days ≈ 2.5B rows at ~50 B each → ~125 GB, manageable when sharded.
- Read/write ratio: >1000:1.
Scope out: payment processing internals, reviews, messaging. Mention them only as downstream consumers of booking events.
Step 2: API Design
GET /v1/search?lat=..&lng=..&radius_km=..
&check_in=2025-07-01&check_out=2025-07-05
&guests=3&price_max=..&cursor=..
-> { results: [{listing_id, title, price_total, rating, thumbnail}], next_cursor }
GET /v1/listings/{id}
POST /v1/listings # host: create
PATCH /v1/listings/{id} # host: update metadata/pricing
PUT /v1/listings/{id}/calendar # host: block/unblock dates, set nightly price
POST /v1/bookings Idempotency-Key: <uuid>
{ listing_id, check_in, check_out, guests, payment_method_id }
-> 201 { booking_id, status: "PENDING_PAYMENT" | "CONFIRMED" }
-> 409 DATES_UNAVAILABLE
GET /v1/bookings/{id}
POST /v1/bookings/{id}/cancel
Key decisions: cursor pagination keeps deep pages stable; the idempotency key makes network-timeout retries safe; 409 signals the client not to retry the same dates.
Step 3: Data Model
Relational store (PostgreSQL), sharded by listing_id:
listings(
listing_id PK,
host_id, title, description,
lat, lng, geohash,
max_guests, base_price, currency,
status, updated_at
)
availability(
listing_id, date,
status ENUM('AVAILABLE','BLOCKED','HELD','BOOKED'),
price,
booking_id NULL,
hold_expires_at NULL,
version INT,
PRIMARY KEY (listing_id, date)
)
bookings(
booking_id PK,
listing_id, guest_id,
check_in, check_out, guests,
status ENUM('PENDING_PAYMENT','CONFIRMED','CANCELLED','EXPIRED'),
total_price,
idempotency_key UNIQUE,
created_at
)
Sharding by listing_id co-locates a listing, its calendar, and its bookings on one shard. This keeps every booking transaction single-shard ACID — no distributed transaction protocol needed.
Guest-facing queries ("my trips") are served from a secondary index keyed by guest_id, updated asynchronously.
Search index (Elasticsearch): one document per listing holding a geo_point, amenities, max_guests, price, quality scores, and availability encoded as a list of blocked date ranges or a 365-bit bitmap.
Step 4: Architecture Overview
Client -> CDN / Global LB -> API Gateway (auth, rate limiting)
├─ Search Service ──> Elasticsearch (geo-sharded, replicated)
│ └─> Redis (hot query cache, short TTL)
├─ Listing Service ──> Listings DB (sharded Postgres) ──┐
└─ Booking Service ──> Calendar/Booking DB ─────────────┤
└─> Payment Service │
CDC (Debezium)
│
Kafka
│
Indexer -> Elasticsearch
Notifications, Analytics
Writes flow only into Postgres. Change data capture (Debezium) streams every mutation through Kafka to an indexer that updates Elasticsearch within a few seconds. This avoids dual writes and prevents silent divergence between the database and the search index.
Step 5: Search Under 200 ms
- Geo filter:
geo_distanceorgeo_bounding_boxagainst geohash-backed indexes prunes to a handful of spatial cells. Query the target cell and its neighbors to avoid edge artifacts. - Hard filters:
max_guests >= guests, price range, amenities — applied as cached filter clauses. - Availability filter: exclude listings with blocked ranges that overlap
[check_in, check_out). The index lags reality by seconds, so a just-booked listing may briefly appear in results. This is acceptable — the booking path re-validates before confirming. - Ranking: take the top few hundred geo-filtered candidates, run a scoring pass (price, rating, relevance), return paginated results.
Latency levers: cache popular city+date queries in Redis (TTL ~30s); shard the index geographically to limit shards hit per query; deploy read replicas per region; precompute total prices at index time.
Step 6: Preventing Double Bookings
The entire booking runs in a single transaction on the listing's shard:
BEGIN;
-- Atomically claim all nights in the range if and only if every night is AVAILABLE
UPDATE availability
SET status = 'HELD',
booking_id = :bid,
hold_expires_at = now() + interval '10 minutes',
version = version + 1
WHERE listing_id = :lid
AND date >= :check_in AND date < :check_out
AND status = 'AVAILABLE';
-- If the row count is less than the requested nights, dates are taken
-- -> application rolls back and returns 409
INSERT INTO bookings (..., status = 'PENDING_PAYMENT', idempotency_key = :key);
COMMIT;
Why this is correct: the conditional UPDATE takes row-level locks on exactly the nights requested. A concurrent request for overlapping dates either waits and finds the rows already HELD, or sees the wrong row count immediately — either way it rolls back. Non-overlapping bookings on the same listing touch different rows and don't contend.
Alternatives worth knowing:
- Postgres exclusion constraint:
EXCLUDE USING gist (listing_id WITH =, stay WITH &&)on a booking row. Elegant and fully database-enforced, at the cost of a GiST index. - Optimistic locking: read the
versionvalues, thenUPDATE WHERE version = :v. Works well when contention is low, which it typically is per-listing. - External lock manager (e.g., Redis Redlock): generally avoid. The database already serializes per-row; an external lock adds failure modes (expiry during GC pauses) without reducing contention.
Step 7: Scaling for Spikes
- Geographic surges: route traffic to the nearest region with a global load balancer (Anycast). Each region runs its own search replicas. Booking writes route to the authoritative shard regardless of region.
- Peak booking windows (New Year sales, holiday weekends): pre-warm the cache, scale out search replicas horizontally, and shed non-critical reads (analytics, recommendation refreshes) via circuit breakers.
- Hot listings: a single popular listing can see thousands of concurrent booking attempts. A short-duration distributed advisory lock per
listing_id(not Redlock — a simple Postgres advisory lock) can serialize attempts cheaply before they hit the row-level update.
Common Mistakes to Avoid
- Dual-writing to both Postgres and Elasticsearch on every booking: creates divergence if either write fails. Use CDC instead.
- Using a distributed lock as the primary concurrency mechanism: the database already provides stronger guarantees at the row level; a lock manager is extra complexity that can fail independently.
- Letting search availability be authoritative: the index is eventually consistent by design. The booking database must be the single source of truth.
- Forgetting hold expiry: a guest who abandons checkout should not block the listing indefinitely. A background job expires
HELDrows back toAVAILABLEafter the hold window.