Amazon Interview Question
SDE-2sCountry: India
Interview Type: In-Person
Movie: Id (Primary Key), title, directory, cast, description, running time
Screen: Id (PK), movie_id (FK (Movie)), theater_id (FK (Theater))
Theater: Id (PK), name, city, state, address, number_of_seats
Seat: Id (PK), Row_Number, Seat_Number, Theater_Id (FK (Theater))
Reserved_Seat: Id (PK), Seat_Id (FK (Seat)), Screen_ID (FK (Screen)), Theater_Id (FK (Theater))
Reservation: Id (PK), Screen_id (FK (Screen)), Reservation_Type (O - Online, W - Window, P - Promotional), Contact, Reserved (Y/N), Payment (Y/N/P (pending)), Active (Y/N)
Here are bunch of API calls
findAll(cities)
findAll(movies)
findMoviesByCity(selected_city)
findTheatersByMovie(selected_movie, selected_city)
findShowtimeByTheater(selected_theater, selected_movie, selected_city)
findAvailableSeats(selected_time,selected_theater, selected_movie, selected_city)
showPrice(selected_seat, selected_time,selected_theater, selected_movie, selected_city)
payForTickets(price, credit_card_details)
bookTickets(selected_seat, selected_time,selected_theater, selected_movie, selected_city, payment_successful_flag)
Regarding concurrent requests, we would need to block the tickets for x min while user is selecting the tickets. This will make sure that there is no double booking. This blocking will only happen when user selects the seats. The finder method calls will give state at the moment when request was invoked with a disclaimer that the state may change and actual state will be displayed at the time of seat booking.
Regarding scalability, the system can be scaled to any number and we can ask qualifying question as what interviewer expects to happen on scalability, whether its regarding supporting multiple vendors or multiple end users. Since our system is micro-service driven each service can work independently and stateless
write following API calls
findAllCities()
findMoviesByCity(selected_city)
findTheatersByMovie(selected_movie, selected_city)
findShowtimesByTheater(selected_theater,selected_movie, selected_city)
findSeatsByShowtime(selected_showtime,selected_theater,selected_movie, selected_city)
findPriceBySeat(selected_seats,selected_showtime,selected_theater,selected_movie, selected_city)
applyLockOnSeats(selected_seats,selected_showtime,selected_theater,selected_movie, selected_city, timestamp)
payForTickets(credit_card_info)
releaseLockOnSeats(selected_seats,selected_showtime,selected_theater,selected_movie, selected_city, timestamp)
bookTicket(selected_seats,selected_showtime,selected_theater,selected_movie, selected_city, user_info)
Regarding concurrent booking, we can run applyLockOnSeats and payForTickets in single transaction and put a lock on seats for x duration
Basic design is to let database handle everything
You can design the backend in following ways
We will use SQL database in the backend,
Seats details are not stored with bookmyshow, once, they have showtime details, they will call custom apis provided by the theaters to get the seats current status.
- sonesh March 29, 2017If they don't have APIs, then, they have two solutions
one is that they manually call those theaters to book the tickets, other would be to save seats details in bookmyshow only and let those theaters book seats based upon bookmyshow page availability, (like, bookmyshow can provide admin page to those theaters to book windows tickets using admin page of bookmyshow only).