Ticket booking project
Created on: Sep 30, 2024
Introduction
A user comes to paytm platform and selects Movie ticket service. Upon selecting the service, they are taken to a page displaying most recent movies. The user can filter movie based on language, genre, check for available bookings and movie tickets.
On selecting a movie, the user is taken to a page showing a list of theatre along with dates and showtimes. Upon choosing an option, the users is redirected to a page displaying available seats. User can select seats and click continue. They will be redirected to a summery page that shows ticket details along with movie information. The user is see an option to proceed to payment. After clicking this button you can see a list of payment options will be displayed. Once the payment is complete the payment, you will see page which display your ticket information.
Technology Stack
In this project we have used Spring boot, Mysql, PostgresSQL and aws cloud(ec2, s3) . Front end part is mixture of react and react native. For load balancing We have used nginx.
High level component
At a high level, the project consist of several microservices including a load balancer, gateway, user service, entertainment service and payment service and notification service.
- Nginx acts as entry point to the system to manage incoming traffic from users. It distribute the load across multiple instances of gateway.
- API gateway acts as a mediator between client request and backend service.
- Entertainment service has multiple module including movie, theatre, show, booking which exposes rest api.
- Payment service handles all the payment related transaction.
- Notification service sends the notification for successful booking, failure booking.
Let's see the various api in entertainment service.
1. **Movie module**: It exposes api to fetch movie details /api/movies= -> fetches a list of movies based on city /api/movie/movieId -> fetches a particular movie 2. **theatre and show module**: APi related to theatre, shows /api/shows -> fetches show details for a particular movie in a particular city. It also return theatre and show timing /api/show/seats -> this shows a list of seat that is available or reserve 3. booking module POST /api/booking -> this is used to book a ticket req body { seatId: List, date: bookingTime: } GET /api/booking -> Fetch all the booked ticket. For all the request above we are sending user information in request header as jwt token.
Understand the booking flow
When a user selects a list of seats and hit booking api, it creates a entry in booking table of mysql for the booking. Also a entry is created in redis with a expiry time of 10 minutes. Since it take some time to book complete the payment flow, we block the seats for that particular user. This is called pessistimic locking. In this case we give 10 minutes timing to complete the payment.
- If payment is successful, that will create a even in kafka and entertainment service will subscribe and mark the booking successful and generate a entry in ticket table. It will remove entry from redis.
- If payment is not successful, payment service will create and event which will be consumer by entertainment service. That will release lock in seat, remove entry from redis and other user can buy ticket.
- If payment is successful and there is a failure in entertainment service to consume the event, retry will happen in entertainment service. Still the problem continue, compensation event will be triggered which will be consumed in payment service to rollback the transaction.
Mysql Schema:
Movie -> movieId, name, description, langauge, genere theatre -> theatreId, city, address Screen -> screeenId, theatreId Seats -> seatId, screenId, rowNo, ColNo
Show -> showId, movieId, theatreId, screenId, startTime ShowSeat-> showSeatId, seatId, isBooked
booking -> bookingId, userId, bookingTime, screenId, theatreId, showId
ticket-> ticketId, bookingTime, showTiming, theatreAdd
Cron Job
We are mysql as a master slave and the data will increase in sql. Since mysql is used for maintaining transaction we will remove the older records from mysql tables to casandra. A cron job will remove old data from booking, movie, show, show seats tables. This is running daily to save the data.
Key Feature:
- Seat selection
- Payment processing Ticket generation
Focus area
- Key features
- DB schema
- Booking strategy -> pessistimic locking, redis ttl explanation
- Various api
- auth part
- Cron job
