System Design ( Day - 25 )

IRCTC System Design
Requirements
1. Train Schedules
2. Search Trains according to timings
3. Book a Single or multiple seats in a train
4. Train Routes with stops and Timings
5. 3 months advanced booking
6. Seating arrangements
7. Handling Parallel seat bookings.
Design
Train Service
Train → Id, noOfSeats, SeatName…
Schedule
Train Id
Source
Destination
Estimated Departure Time (EDT)
Estimated Arrival Time (EAT)
Search Train Service
Query → Source → Destination, Start Date and Time
We have to do query on the Source and Destination and then after that we have to filter with the Start Date and time according to the user. for that train we have to get the route from that source and destination with its arrival and departure time for every stop that train has, this is a separate Api these are the two queries which helps to search and get the train for a particular date and time along with it’s stops and time, these train schedules and stops are stored in a Sql database, and we’ll get it from there when the user searched for the particular train at particular date, we have to get all the trains for that particular source to destination at that date in which user has searched, we can do that because the trains schedule and dates are not frequently changed
They are same for the longer period of time so that won’t be an issue, and then coming to the arranging the seat for the booking, we have to show available seats for the selected source and destination like The train goes from A to M there are 500 seats available for this train but we have stops for that train, like B, C, D etc.. are the stops for that train, we have to allot a booking from A to G for the seat S10-G15 then for that train for that seat that slot has to be alloted for that user, and after the station G which is H - M should be free like that if a user wants to book a seat from the source H to M then this seat should be available for that user to book, the users can book in a different ways for that we have to handle the booking of seats in a specific chunks to have concurrency, and also the allotment of the seats could be random according to the availability of the seats in the train, we can fill from first to last or last to first or randomly that is totally depending on the designer no i’m taking it as first to last, like from first compartment to last compartment of the Train.
If a user books a seat then we can allot the seat number and compartment after 2 days or 5 days before the starting date or after some time, it’s not necessary to give then the seat number instantly, we can take time for that one because we are allotting from first compartment to last, so for that we can have a queue of booking requests from the user after servicing one request we can server another so that the system load is been reduced, after that the ticket will be issued for that user after allotting that seat for that journey for that journey we have to lock that seat to that user only, after source and destination complete that seat should be unLocked that means it could be booked by some other people, we have to allow them to book after unLocking that seat.
For this i have to maintain a table for Route with source and destination along with time and available seats, we have 2 seats left in a train the train goes from A - D one user wants booking from A - C another user wants a booking from B - D then we have to lock the seat from A - C for first user and then we have to unlock after C its D, that seat is available from C - D the second seat is available from A - B because the Second user is booked from B - D, like this way we can maintain by increasing and decreasing the available seats to lock and unlock the no of seats available in a Train, If a user wants to cancel the booking then with no charges or minimal charges before 1 week from the starting date we have to allow that user to cancel that booking, and increase the available seats in that train, if the user wants to cancel the booking like 12 hours before then that user can’t able to cancel the booking, or the user won’t get any refund or we don’t change the available seats left also.
This is a High level design of IRCTC, still there are so many things to discuss like tatkal, different coach, like AC 1st , 2nd and so on, IRCTC is not just booking a train there lot of things could happen so if happens then ill discuss in further articles.
Thank You
Subscribe to my newsletter
Read articles from Manoj Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
