Design a Real-Time Event Venue Booking Platform Architecture
System DesignModel answerLast updated
Design a high-level architecture for an event venue reservation platform, focusing on double-booking prevention, concurrency control, and interval-based storage.
Scenario
Design a venue reservation platform (similar to Peerspace or event space booking engines) where hosts publish spaces (conference halls, banquet rooms, shooting studios) and renters reserve them for specific dates or hourly timeslots.
Key Requirements
Functional Scope
- Venue Management: Hosts can manage listings, define standard business hours, set daily/hourly base prices, and configure blackout periods.
- Venue Discovery: Renters can query and filter spaces using parameters such as geographical proximity, guest capacity, hourly rate, time window, and required features/amenities.
- Reservation & Concurrency Prevention: Renters can lock an available slot temporarily (e.g., a 10-minute hold) to complete payment. Once paid, the booking is finalized. Double-booking any venue for overlapping times must be impossible.
- Lifecycle Operations: Manage status transitions across the reservation pipeline:
HELD,CONFIRMED,CANCELLED, andEXPIRED.
Operational Expectations
- Consistency Guarantees: Strict serializability / strong consistency for reservation states to ensure zero double-bookings. Searching and browsing can accept eventual consistency.
- Availability & Performance: Browsing endpoints must handle heavy traffic resiliently.
- SLA Limits: Search API latency must stay under 200ms (p95); creation of a temporary hold must respond within 500ms (p95).
System Scale
- Scale: 5,000,000 active venue listings globally.
- Traffic: 30 million daily active users (DAU); 50 million search requests per day (~600 QPS average, 3,000 QPS peak).
- Reservations: 500,000 temporary holds/bookings attempted daily (~6/sec average, 100/sec peak).
- Read-to-Write Ratio: Heavily read-skewed (~100:1 read/write balance).
Focus Areas
- API Endpoints: Interfaces for searching venues, acquiring temporary holds, and finalizing payments.
- Data Storage & Range Modeling: Schema strategy for listings vs. schedule windows (e.g., comparing discrete time slots vs. continuous time ranges).
- Architecture Overview: Complete topology encompassing search engines, core transactional services, caching strategy, and asynchronous queues.
- Race Conditions & Concurrency: Mechanisms for guaranteeing mutual exclusion when multiple users target the exact same venue and time window simultaneously.
Hints
Hint 1
Separate the search read path (eventually consistent) from the reservation write path (strongly consistent).
Hint 2
Consider PostgreSQL PostgreSQL range types (`TSTZRANGE`) and `EXCLUDE` constraints to enforce non-overlapping time windows directly at the storage level.
Hint 3
Implement temporary holds using short-lived database rows combined with lazily evaluated expiration logic to avoid relying solely on external distributed locks.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. System Requirements & Scale Analysis
Traffic & Capacity Calculation
-
Read Workload (Search & Detail Views):
- 50M searches/day $\approx$ 600 average QPS.
- Peak traffic (5x multiplier) = 3,000 QPS.
- A well-tuned Elasticsearch/OpenSearch cluster distributed across a few nodes handles 3,000 QPS easily.
-
Write Workload (Holds & Finalized Reservations):
- 500,000 hold attempts/day $\approx$ 6 writes/sec average.
- Peak traffic = 100 writes/sec.
- At 100 QPS, a single primary PostgreSQL instance handles the transaction volume cleanly. Hotspot contention occurs on individual popular venues rather than global database throughput.
-
Storage Overhead:
- Venues: $5\text{M} \times 10\text{ KB} \approx 50\text{ GB}$. Standard relational storage fits this in memory easily.
- Bookings: $500\text{K}/day \times 1\text{ KB} \approx 180\text{ GB/year}$. Simple horizontal partitioning or table partitioning by year handles multi-year growth.
2. API Design
Search Venues
GET /v1/venues/search?lat=37.7749&lng=-122.4194&radius_km=10&min_capacity=50&start=2025-06-15T14:00:00Z&end=2025-06-15T18:00:00Z&amenities=wifi,projector&page_token=eyJ...
Response (200 OK):
{
"venues": [
{
"venue_id": "v_8f9a2b",
"title": "Downtown Innovation Loft",
"hourly_rate_cents": 15000,
"estimated_total_cents": 60000,
"currency": "USD",
"thumbnail_url": "https://cdn.example.com/v_8f9a2b/thumb.jpg"
}
],
"next_page_token": "eyJvZmZzZXQiOjIwfQ=="
}
Acquire Temporary Hold
POST /v1/holds
Idempotency-Key: 7b8893c1-0c3a-442a-a241-d603a123f81e
{
"venue_id": "v_8f9a2b",
"start_time": "2025-06-15T14:00:00Z",
"end_time": "2025-06-15T18:00:00Z",
"attendees": 40
}
Response (201 Created):
{
"booking_id": "bk_993810",
"status": "HELD",
"held_until": "2025-06-15T10:10:00Z",
"pricing": {
"subtotal_cents": 60000,
"service_fee_cents": 6000,
"total_cents": 66000,
"currency": "USD"
}
}
Error Response (409 Conflict):
{
"error": "SLOT_UNAVAILABLE",
"message": "The selected venue is unavailable for the requested timeframe."
}
Confirm Reservation
POST /v1/bookings/bk_993810/confirm
Idempotency-Key: e49a3182-1092-4d22-b21a-29177fa21182
{
"payment_intent_id": "pi_3MtwB2LkdIwRFi720lX4529d"
}
Response (200 OK):
{
"booking_id": "bk_993810",
"status": "CONFIRMED",
"confirmed_at": "2025-06-15T10:05:12Z"
}
3. Data Storage & Range Strategy
Discrete Slots vs. Continuous Intervals
| Parameter | Discrete Slot Approach (30-min Blocks) | Continuous Interval Approach (TSTZRANGE) |
|---|---|---|
| Storage Density | High storage volume: $48\text{ slots/day} \times 365\text{ days} \times 5\text{M venues} = 87.6\text{B rows/yr}$. | Low storage volume: Exactly 1 row per booking/hold. |
| Granularity | Locked to predefined boundaries (e.g., fixed 30-min increments). | Completely variable durations (e.g., 1 hr 15 mins, customized teardown buffers). |
| Double-Booking Guards | Requires updating/locking multiple discrete slot records in sequential order to avoid deadlocks. | Relies on relational Exclusion Constraints (GiST index over ranges). |
| Search Engine Filtering | Efficient bitmask representation in search indices. | Interval overlap queries require higher indexing overhead in Elasticsearch. |
Verdict: Use Continuous Intervals (TSTZRANGE) inside the primary transactional relational store as the single source of truth. Derive discrete slot availability bitmasks for search indexing inside Elasticsearch to keep query latencies sub-200ms.
Relational Schema Design (PostgreSQL Engine)
CREATE TYPE booking_status AS ENUM ('HELD', 'CONFIRMED', 'CANCELLED', 'EXPIRED');
CREATE TABLE venues (
venue_id VARCHAR(64) PRIMARY KEY,
host_id VARCHAR(64) NOT NULL,
title VARCHAR(255) NOT NULL,
location GEOGRAPHY(POINT, 4326) NOT NULL,
capacity INT NOT NULL,
hourly_rate_cents INT NOT NULL,
buffer_minutes INT DEFAULT 0,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE bookings (
booking_id VARCHAR(64) PRIMARY KEY,
venue_id VARCHAR(64) REFERENCES venues(venue_id),
guest_id VARCHAR(64) NOT NULL,
during TSTZRANGE NOT NULL, -- Stored in UTC, inclusive of teardown buffers
status booking_status NOT NULL DEFAULT 'HELD',
held_until TIMESTAMPTZ,
price_cents INT NOT NULL,
idempotency_key VARCHAR(128) UNIQUE,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
-- Prevents overlapping time windows for active/held states
CONSTRAINT no_overlapping_active_bookings
EXCLUDE USING gist (
venue_id WITH =,
during WITH &&
) WHERE (status IN ('HELD', 'CONFIRMED'))
);
4. High-Level Architecture
+-------------------+
| Client Apps |
+---------+---------+
|
v
+-------------------+
| API Gateway/CDN |
+----+---------+----+
| |
+--------------+ +--------------+
| |
v v
+-----------------------+ +-----------------------+
| Search Service | | Booking Service |
+-----------+-----------+ +-----------+-----------+
| |
+------------+------------+ v
| | +-------------------+
v v | PostgreSQL Primary|
+--------------+ +--------------+ | (Exclusion Locks)|
| Elasticsearch| | Redis Cache | +---------+---------+
| Search Index| | (Hot Queries)| |
+--------------+ +--------------+ v
+------------------+
| CDC / Debezium |
+--------+---------+
|
v
+------------------+
| Kafka Topics |
+--------+---------+
|
v
+------------------+
| Indexer Worker |
+------------------+
Component Breakdown
-
Search Flow:
- Client queries the Search Service.
- Checks Redis for cached common queries.
- On cache miss, queries Elasticsearch, which holds geographical spatial coordinates, capacities, feature flags, and derived 30-minute interval availability bitmasks.
- Returns listings quickly to satisfy the < 200ms p95 latency goal.
-
Hold Creation Flow:
- Client issues
POST /v1/holdsto the Booking Service. - Open transactions clean up stale overlapping holds for that venue lazily, then attempt row insertion.
- Primary DB checks the Exclusion Constraint (
EXCLUDE USING gist). - If success $\rightarrow$ return
201 HELD. If collision $\rightarrow$ return409 CONFLICT.
- Client issues
-
Data Synchronization:
- PostgreSQL write logs trigger Debezium CDC (Change Data Capture) streaming to Kafka.
- Consumer workers read updates asynchronously to calculate updated bitmasks and re-index updated schedules in Elasticsearch.
5. Concurrency & Race Condition Deep Dive
Resolving Overlapping Hold Attempts
To ensure two users cannot secure the same space for overlapping intervals:
BEGIN;
-- Step 1: Lazily transition expired holds for this venue to allow new requests through
UPDATE bookings
SET status = 'EXPIRED'
WHERE venue_id = 'v_8f9a2b'
AND status = 'HELD'
AND held_until < NOW();
-- Step 2: Attempt insertion of the new temporary hold
INSERT INTO bookings (booking_id, venue_id, guest_id, during, status, held_until, price_cents, idempotency_key)
VALUES (
'bk_993810',
'v_8f9a2b',
'guest_441',
TSTZRANGE('2025-06-15 14:00:00+00', '2025-06-15 18:00:00+00', '[)'),
'HELD',
NOW() + INTERVAL '10 minutes',
60000,
'7b8893c1-0c3a-442a-a241-d603a123f81e'
);
COMMIT;
Why Exclude Constraints Triumph Over Distributed Locks
- Using pure distributed locks (e.g., Redis Redlock) introduces potential race conditions during network partitions, long process pauses (GC), or clock skews.
- Relational Exclusion Constraints lock at the transactional storage boundary. PostgreSQL uses
GiST(Generalized Search Tree) indexes on range types to guarantee that no two overlapping rows matching the filter condition (status IN ('HELD', 'CONFIRMED')) coexist.
Finalizing Payment & Hold Expiration
- Hold Check: When a user triggers confirmation (
POST /v1/bookings/bk_993810/confirm), payment authorization is evaluated first. - Atomic Status Update:
UPDATE bookings SET status = 'CONFIRMED', held_until = NULL WHERE booking_id = 'bk_993810' AND status = 'HELD' AND held_until > NOW(); - Handling Expiration:
- If
UPDATEmodifies 1 row, finalize payment capture. - If
UPDATEmodifies 0 rows, the hold expired mid-checkout. Reverse/void payment authorization and return410 HOLD_EXPIRED.
- If
6. Edge Cases & Resilience Strategy
-
Abandoned Holds:
- A scheduled background sweeper worker periodically queries
status = 'HELD' AND held_until < NOW()to mark rowsEXPIREDin bulk. - On-demand lazy updates during new hold creation ensure users are never blocked by background worker execution lag.
- A scheduled background sweeper worker periodically queries
-
Search Index Desynchronization:
- Elasticsearch indices update asynchronously via CDC/Kafka pipelines. A slot shown as available in search results might already be held by another user.
- Resolution: Search results are treated as informational hints. Strong consistency checks occur during the
POST /v1/holdstransaction.
-
Network Retries & Duplication:
- All state-changing endpoints require an
Idempotency-Keyheader. - Deduplication layers cached in Redis or enforced via unique table constraints ensure retried requests process identically without duplicate entries.
- All state-changing endpoints require an