System requirements
Functional:
- Search movie theatre
- search movie screens
- search movie ticket
- purchase ticket
- US only
Non-Functional:
- ACID compliance
- SQL Database for payments & tickets
- Availability and eventual consistency
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
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
High-level design
- DB
- Meta Data - Dynamo DB
- Booking/Payment - SQL
- Movies - Dynamo DB
- Queuing
- Kafka
- to process the request one at a time to avoid concurrency issue
- 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 attact
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
- 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
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
- rate the movies using their profile
- review using the profile