Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save valarpirai/2ed5cb85976b17b36ac7addf2d1d1665 to your computer and use it in GitHub Desktop.

Select an option

Save valarpirai/2ed5cb85976b17b36ac7addf2d1d1665 to your computer and use it in GitHub Desktop.
Summary of system design round summary

Here's a clean, concise summary of the key steps to design a Ticket Booking System (like BookMyShow or Ticketmaster) in a system design interview:

1. Clarify Requirements (5–8 mins)

  • Functional: Browse/search events by city/date/category → View seat map → Select & hold seats → Make payment → Confirm booking → View/cancel bookings.
  • Non-Functional: Handle high concurrency (flash sales), prevent double-booking (strong consistency for seats), low latency, high availability (99.99%), scalability to 10k–100k+ RPS at peak.
  • Ask about scale, payment integration, cancellation rules, admin features.

2. Back-of-the-Envelope Estimation

Estimate:

  • Daily active users, peak RPS during sales.
  • Number of events, seats per show.
  • Storage needs (bookings, media).
  • QPS for seat availability vs booking.

3. High-Level Architecture

  • Microservices approach: User Service, Event/Catalog Service, Inventory/Seat Service, Booking Service, Payment Service, Notification Service.
  • API Gateway + Load Balancer in front.
  • Use event-driven design with Kafka/SQS for async communication.
  • Separate read path (availability) and write path (booking) → often using CQRS.

4. API Design (REST)

Key endpoints:

  • GET /events?city=...&date=...
  • GET /events/{id}/shows/{showId}/seats (seat map)
  • POST /seats/hold (temporary seat lock)
  • POST /bookings + payment flow
  • POST /bookings/{id}/confirm or webhook

5. Database Design

  • PostgreSQL/RDS (ACID transactions): Tables for Users, Venues, Events, Shows, Seats, Bookings, Booking_Seats, Payments.
  • Redis/ElastiCache for fast seat availability and temporary holds (TTL-based).
  • DynamoDB for high-scale read/write on inventory if needed.
  • Indexes on show_id + seat_number.

6. Core Flow – Booking Process (Most Important)

  1. User views seat map (read from cache/DB).
  2. User selects seats → Atomically hold seats (temporary reservation with 10–15 min expiry).
  3. Create pending booking.
  4. User proceeds to payment.
  5. On payment success → Confirm booking, mark seats as booked, release other holds.
  6. On timeout/failure → Auto-release holds via background job.

Concurrency Handling (critical part):

  • Optimistic locking (version column)
  • Pessimistic locking (FOR UPDATE)
  • Redis Lua scripts or distributed locks
  • Idempotency keys

7. Scalability & Resiliency

  • Horizontal scaling of services + Auto Scaling.
  • Caching (Redis) + CDN (CloudFront) for static assets/seat maps.
  • Sharding by show_id or city.
  • Circuit breakers, retries, Saga pattern for distributed transactions.
  • Rate limiting & virtual waiting room for flash sales.

8. AWS Services (Production-Ready)

  • API Gateway + ALB
  • ECS/EKS or Lambda for services
  • RDS PostgreSQL (Multi-AZ) + DynamoDB
  • ElastiCache Redis
  • SQS/MSK (Kafka) for background jobs
  • S3 + CloudFront for images/tickets
  • Step Functions for orchestration
  • CloudWatch + X-Ray for monitoring

9. Additional Components

  • Background Jobs: Release expired holds, send notifications (email/SMS/push), generate e-tickets, aggregate analytics.
  • Analytics: Real-time (Kinesis) + batch (Redshift/Athena) for sales, revenue, user behavior.
  • Notifications & Payments: Integrate Stripe/Razorpay + SNS/SQS.

10. Trade-offs & Deep Dives

  • Consistency vs Availability (strong consistency only for booking path).
  • Handle edge cases: Payment failure, partial booking, network issues, bots/fraud.
  • Improvements: Search with Elasticsearch, recommendations, multi-region.

Pro Tip for Interview: Always structure your answer as: Requirements → Estimation → High-Level Design → API + DB → Deep Dive (especially concurrency & booking flow) → Scalability → Trade-offs.

This covers the end-to-end design efficiently in 45–60 minutes.

Would you like me to expand any single step (e.g., only concurrency handling, or only AWS setup), or provide a visual text diagram of the architecture? Let me know!

@valarpirai
Copy link
Copy Markdown
Author

If time permits, explain following also

  • Security
  • Failure Handling
  • Notification etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment