System requirements
Functional:
- Search movie theatre
- search movie screens
- search movie ticket
- purchase ticket
- US only
Non-Functional:
- ACID compliance
- SQL Database for payments & booking confirmation
- Availability and eventual consistency
- No-SQL Database
- to store meta data
Capacity estimation
- Daily Active Users - 10million/month
- Throughput - 10,000,000/86200=111 user/sec
- Storage
- Meta data - 100 GB/month
- meta data - 1 TB/Year
- Memory
- Redis
- 100GB data
API design
- Get
- User ID
- Location ID
- Movie ID
- Showtime ID
- Availability
- Date
- Time
- Request
- User id
- Location ID
- Movie ID
- Showtime ID
- Book ID
- Date
- Time
- Booking confirmation ID
- Not available return error code 404
Database design
- SQL DB schema
- User ID
- movie name
- number of tickets
- show date
- show time
- seat number
- amount
- booking ID
- No-sQL DB schema
- user ID
- first name
- last name
- phone number
- create one more table to merge
- user id
- booking ID
- seat number
High-level design
Non-Functional requirement -
- Data Base
- Meta Data - Dynamo DB
- user profile
- Booking/Payment - SQL
- link user profile against the booking confirmation
- Movies - Dynamo DB
- search movies based on the state/city or zip code
- Queuing
- Kafka
- sequence the user request one at a time to based on first come basis
- Load Balancer - AWS Elastic load balancing/nginx
- distribute the traffic based on the request to app servers using round robin strategy
- Elastic load balancing automatically manages the traffic to appropriate servers
- API server
- Metadata
- Movie DB
- Booking confirmation DB
- Cache
- Redis
- Add new frequently searched to the list
- remove least searched movies
- remove movies that has expired time
- Horizontal
- Hash based sharding
- hash all the booking ID with appropriate key for easy look up of the booking confirmation along with the user data
- linked hash map
- assign a certain time window to hold the reservation for 5 minutes until payment is complete if not remove the reservation hold
- Fault Tolerance
- Leader
- replicate the servers to avoid single failure point of failure
- add servers across multiple region for nearest location and eliminate latency
- Follower
- select the next available server in case of the primary failure
- Rate limiter
- prevent multiple request from the same client
- prevent bot attack
- Security
- user authentication through registration using user id as email along with password
- lock the account if the password fails after 5 attempts
- Metrics & analytics logs
- Datadog/Grafana - We can pull logs from all the services and monitor them in a dashboard
Functional requirement
- Search movies based on the location - state/city or zip code
- Reservation count/Seat selection
- user can reserve a total of 10 seats at one time
- seat selection -
- select even number of seats in the count of 2
- select in a available sequence first if not available then select randomly
- Booking & payment confirmation
- Ticket will wait in the check out queue for 5 minutes until the payment is made
- Once the payment is made the ticket is confirmed and a booking id is generated against it
Request flows
- Meta DB
- Movie DB
- movie theatre service
- check out service
- payment service
Detailed component design
- Dynamo DB
- Kafka
- Kafka
- For asynchronous communication between microservices, we will leverage Kafka as a distributed messaging system. Kafka’s fault-tolerant and scalable architecture makes it ideal for handling large volumes of data and ensuring reliable message delivery
- we can have multiple producer and consumer request queue based on the FIFO strategy
- if one of the queue fails then take the last failed request to a different queue and start processing from there based on the time
- Horizontal sharding
- Hash based sharding
- hash all the booking ID with appropriate key for easy look up of the booking confirmation along with the user data
- linked hash map
- assign a certain time window to hold the reservation for 5 minutes until payment is complete if not remove the reservation hold
- eliminates concurrency issue in DB
- Payment Gateway
- for credit card payments we can have third party service provider such as stripe/adyen for security reasons and confirm the payment
Trade offs/Tech choices
- Dynamo/ CasandraDB
- No-SQL
- for storing the meta db with additional information as we scale
- Dynamo DB automatically scales based on the load
- replicates copies across multiple regions
- fail safe to different region if one of the server goes down
Failure scenarios/bottlenecks
Future improvements
- Bulk booking
- Refund
- different payment methods - apple/google
- rate/review the movies using the profile