Circle.
Core Requirements
- Users should be able to view events
- Users should be able to search for events
- Users should be able to book tickets to events
Below the line (out of scope):
- Users should be able to view their booked events
- Admins or event coordinators should be able to add events
- Popular events should have dynamic pricing
Non-Functional Requirements
Core Requirements
- The system should prioritize availability for searching & viewing events, but should prioritize consistency for booking events (no double booking)
- The system should be scalable and able to handle high throughput in the form of popular events (10 million users, one event)
- The system should have low latency search (< 500ms)
- The system is read heavy, and thus needs to be able to support high read throughput (100:1)
Below the line (out of scope):
- The system should protect user data and adhere to GDPR
- The system should be fault-tolerant
- The system should provide secure transactions for purchases
- The system should be well tested and easy to deploy (CI/CD pipelines)
- The system should have regular backups
Event {
id
venueId (foreign key)
performerId
tickets[]
name
description
}
Venue {
id
location
seatmap
}
Performer {
id
}
Ticket {
id
eventId
seat
price
status: enum
userId
reserved timestamp (one option)
}
Booking
APIs
- GET /event/:eventId -> Event & Venue & Performer & Ticket[]
- GET /search?term={}&location={}&type&date -> Partial[]
- POST /booking/reserve
body: {ticketId}, no userId in post body, header JWT or session token - PUT /booking/confirm
body: {ticketId, payment}
For ticket reservation status, need real time update.
- reserved timestamp
- cron job, delta
- distributed lock (redis), ttl.
{ticketId: true} TTL 10 min. Failure, in small 10 min window, some users may not be able to book, first one wins. Discuss with product team.
Define one-three places to show off. Look at non-functional requirements and see what is missing.
- Low latency search. Search optimized database: elastic search (tokenize event). For example,
playoff: [event1, event2]. Geospatial search using both hashing and quad trees. Usually not as primary datastore. Write throughput might be low. In this use case, write traffic is low. AWS opensearch node query caching.- application write to both db and elastic search
- change data capture, use queue if write is a concern.
- popular queries: caching. no personal ranking and recommendation. Or redis in front of elastic search. or cdn cache API calls (less useful if more permutations are in the search, low cache hit).
- client click on seat 5 minutes later, no longer available. 1) long pulling to publish updates to client. 2) persistent connection: websockets or server sent events (SSE).
- introduce choke point (admin enabled), virtual waiting queue (Redis sorted set or other a bit randomized, not just people closest to our servers) for popular events ticket booking. SSE to notify them out of queue.
- Scaling: load balancer, dynamic, horizontally, math, back of the envelope calculations. Do we need to shard PostgreSQL, shard on eventId or venueId.
- Redis cache for event, venue, performer since they don't change as frequently. eventId: {event, venue, .etc}
- Hello Interview Ex Meta https://www.youtube.com/watch?v=fhdPyoO6aXI

