Design TicketMaster system

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-11-22

Problem Statement

Design TicketMaster, a large-scale, event-ticket booking platform that allows users to browse events, select seats, and purchase tickets for concerts, sports, theater, and other live events — all in real time and with high reliability under flash-sale conditions.


🎯 Objective


Build a scalable, highly available ticketing platform that supports:


•Real-time event discovery and seat selection
•Atomic ticket booking and payment confirmation
•Seat-locking to prevent double booking
•Handling of high traffic spikes during popular event sales


✅ Functional Requirements


1. Event Management


•Organizers can create events (name, venue, date/time, seating map, ticket price tiers).
•Events can have multiple showtimes or categories (VIP, Gold, Silver, etc.).


2. Event Discovery


•Users can search, filter, and browse events by city, date, category, or performer.
•Show event details (venue layout, seat availability, pricing, etc.).


3. Seat Selection & Locking


•Users can view a real-time seating chart.
•When a user selects a seat, it is temporarily locked (seat hold) for a short duration (e.g., 2 minutes).
•Locked seats cannot be selected by others during the hold period.
•If the user does not complete payment within the time window, the lock expires and seat becomes available again.


4. Booking & Payments


•Once a user confirms seats, the system:
1.Validates seat availability
2.Processes payment (via external payment gateway)
3.Confirms booking and issues e-ticket (QR code or PDF)
•Each booking is atomic — either all selected seats are booked or none.


5. Notifications


•Send confirmation email/SMS upon successful booking.
•Notify user if booking fails or seat lock expires.


6. Cancellations & Refunds


•Allow cancellations (subject to event rules) and process partial or full refunds.


7. Admin Portal


•Event organizers can view sales, manage events, and analyze bookings.


⚙️ Non-Functional Requirements


| Requirement | Description |

| ---------------- | -------------------------------------------------------------------------- |

| **Scalability** | Must handle millions of users and flash-sale surges (e.g., concert drops). |

| **Consistency** | Strong consistency needed for seat availability & booking. |

| **Latency** | Seat selection and availability checks must complete in < 200 ms. |

| **Reliability** | No double-bookings; fault tolerance during booking/payment. |

| **Availability** | ≥ 99.99% uptime for booking and event browsing. |

| **Security** | Secure payments, user data encryption, fraud detection. |

| **Durability** | Ticket data and payments must never be lost. |


🧠 Key Components to Design

1. Event Service

•CRUD operations for events and venues.
•Stores event metadata (title, category, schedule, pricing).
•Venue layout and seat map stored separately for quick seat lookup.

2. Search & Discovery Service

•Handles event search by name, artist, location, category, or date.
•Uses Elasticsearch or Solr for full-text indexing.
•Results cached in Redis for popular searches.

3. Seat Inventory Service

•Maintains real-time seat availability.
•Uses strong consistency (e.g., SQL with row-level locks) or Redis atomic operations for seat locking.
•Stores:
•Seat status: AVAILABLE, LOCKED, BOOKED
•Lock expiry timestamps
•Exposes APIs:
•lockSeat(user_id, seat_id)
•releaseSeat(seat_id)
•confirmSeat(seat_id, booking_id)

4. Booking Service

•Coordinates booking workflow:
•Validate seat lock
•Call Payment Service
•Confirm or rollback transaction
•Ensures idempotency to prevent double payments/bookings.
•Uses message queues (e.g., Kafka/SQS) to handle async confirmations.

5. Payment Service

•Integrates with third-party gateways (Stripe, Razorpay, etc.).
•Supports retries and rollback in case of failure.
•Uses secure tokenization for card data.

6. User Service

•Handles user profiles, login, preferences, booking history.

7. Notification Service

•Sends booking confirmations, refunds, seat-lock expiry alerts via email/SMS/push.

8. Analytics Service

•Tracks sales, conversion rates, and traffic metrics for event organizers.

🧩 Data Model (Example)

Event Table

| Field | Type | Description |

| ---------- | --------- | ---------------------- |

| event_id | UUID | Primary key |

| name | String | Event title |

| venue_id | UUID | Venue reference |

| start_time | Timestamp | Event start |

| category | String | Concert/Sports/Theatre |

| status | Enum | Active/Cancelled |


Seat Table

| Field | Type | Description |

| ----------- | --------- | --------------------------- |

| seat_id | UUID | Primary key |

| event_id | UUID | Associated event |

| seat_number | String | e.g. A12 |

| section | String | e.g. Balcony |

| price | Decimal | Seat price |

| status | Enum | AVAILABLE / LOCKED / BOOKED |

| lock_expiry | Timestamp | Lock TTL |


Booking Table

| Field | Type | Description |

| ---------- | --------- | ---------------------------- |

| booking_id | UUID | Primary key |

| user_id | UUID | User reference |

| event_id | UUID | Event booked |

| seats | JSON[] | Seat list |

| amount | Decimal | Total |

| status | Enum | PENDING / CONFIRMED / FAILED |

| created_at | Timestamp | Timestamp |


🧱 High-Level Architecture

1 2 ┌──────────────────┐ 3 │ Web / Mobile │ 4 │ Clients │ 5 └────────┬──────────┘ 6 │ 7 ┌──────┴────────────────────────┐ 8 │ API Gateway │ 9 └──────┬────────────────────────┘ 10 │ 11 ┌───────────────┼─────────────────────────────┐ 12 │ │ │ 13 │ Booking Service Event Service 14 │ │ │ 15 │ Seat Inventory Service Search Service 16 │ │ │ 17 │ Payment Service User Service 18 │ │ │ 19 │ Notification Service Analytics Service 20 └───────────────┼─────────────────────────────┘ 21 │ 22 ┌──────┴───────────┐ 23 │ Database Cluster │ 24 │ (SQL + Redis) │ 25 └──────────────────┘ 26 │ 27 ┌──────┴───────────┐ 28 │ Message Queue │ 29 │ (Kafka/SQS) │ 30 └──────────────────┘


🚀 Scalability & Optimization


•Seat Locking: Use Redis distributed locks (SETNX) for atomic locking.
•High Concurrency: Shard seat inventory by event_id.
•Caching: Redis cache for hot events and popular venues.
•CDN: Serve event images, posters, and static assets globally.
•Async Processing: Use Kafka for payment confirmation, email notifications, analytics.
•Database Scaling:
•Master-slave replication for read/write separation.
•Partition booking and seat tables by event_id.
•Failover: Replicated databases with automatic failover.


🔐 Security Considerations


•OAuth 2.0 for authentication.
•PCI-compliant payment handling.
•Tokenized APIs for communication between services.
•Rate limiting and CAPTCHA for bot prevention during flash sales.


⚠️ Failure Scenarios & Mitigations


| Failure | Mitigation |

| ----------------- | --------------------------------------------------- |

| Double booking | Redis atomic seat lock + transaction rollback |

| Payment timeout | Use async confirmation via message queue |

| Service crash | Retry via idempotent booking IDs |

| Lock not released | Use TTL-based expiry |

| Surge traffic | Auto-scale services & use distributed load balancer |


✅ Final Deliverable:

A fault-tolerant, real-time, and scalable event ticketing system that supports seat-level booking, real-time availability, and reliable payments under high-traffic conditions — like TicketMaster or BookMyShow.

Solution

Comments