1) User should be able to view available movies and
seats within a movie show
2) Users should be able to book tickets
3) Users can view their bookings
4) Search for a movie or theater
1) Low latency for search
2) Handle concurrent bookings to avoid over/double booking
3) Scalable for high throughput in case of famous events
-> Assume 100M users and 10% of DAU
write TPS : 10M / 0.1M ~= 100QPS
read TPS 10* write ~= 1000QPS
peak time write TPS : 500QPS (5x)
peak time write TPS : 50000QPS
Storage :
each booking event storage 1kb around :
per day : 100M * 1kb ~= 100GB
per year : 365*100GB = 40TB
search for events :
GET /v1/event?name=n&location=l& .. etc query params
returns list of events
book a ticket :
POST /v1/event/{e_id}/bookings
Request :
{
ticket_ids :
payment_details :
}
get event details :
GET /v1/event/{e_id}
use SQL DB for ACID capabilities
event : id, name,desc,performer, venue,date
ticket : id,event_id, booking_id, seat,price,status
bookings : id, event_id, list of tickets, user_id
User : id,name,email,pwd_hash
This diagram represents a ticket booking system designed to handle:
Here’s how each component works to solve the ticket booking problem:
1) Get event details : user requests via API, gateway will send it to event service which looks up redis cache first and then to postgres DB event table.
2) Search for event : Search service will query elastic search DB and give the result based on text and date. data b/w elastic search & postgres is replicated via kafka.
3) Book ticket : booking service will acquire distributed lock via redis(with TTL) and make a booking and update bookings table. payment can be done via 3rd party API.
I don't think for a HLD interview we need to dig deep into component design, skipping it for now
Postgres is used as DB because of its ACID properties, but with high writes it may be a bottleneck. we can shard data appropriately and use read replicas to handle read traffic.
Elastic search is used for full text search/fuzzy search which improves latency of searches.
This may cause operational overhead and costs associated.
kafka is used to replicate data b/w postgres and elastic search.
Redis is used for distributed locking. It is quick and in memory so it reduces latency. But it can crash sometime causing issue.
We can use redis sential to monitor redis availability and make a replica as leader
Postgres can be a bottleneck with heavy writes.
redis can be bottleneck if its crashes.
data consistency b/w elastic search and postgress, postgres and redis cache can be a issue if not handled properly.
Already mentioned above how we an overcome