Railway Ticket Booking System
Problem Statement
Design the Low-Level Design (LLD) for a Railway Ticket Booking System (similar to IRCTC) that allows passengers to search trains, check seat availability, book tickets, cancel bookings, and view booking history.
The system should efficiently handle concurrent bookings, seat allocation, and waiting list management, ensuring data consistency and fair allocation of seats.
🎯 Core Requirements
1. Train Management
2. Search and Availability
3. Booking
4. Cancellation
5. Booking History
⚙️ Functional APIs
OperationDescription
searchTrains(source, destination, date)
Returns list of trains for a route.
checkAvailability(trainId, date, classType)
Shows available seat count.
bookTicket(trainId, userId, passengerList, classType)
Books ticket and returns PNR.
cancelTicket(pnr)
Cancels the booking and reallocates seats.
getBookingHistory(userId)
Lists all bookings made by a user.
🧱 Suggested Class Design
ClassResponsibility
Train
Represents a train, route, and classes of seats.
Coach/ClassType
Represents a specific coach type (Sleeper, AC).
Seat
Represents a single seat with number and status (Available/Booked).
Passenger
Represents passenger details (name, age, gender).
Booking
Represents a booking record (PNR, train, user, passengers, status).
User
Represents user account and booking history.
BookingService
Handles booking, cancellation, and seat allocation logic.
TrainService
Handles train search, schedule, and seat availability.
PNRGenerator
Generates unique PNRs.
WaitingListManager
Manages queue for waiting passengers.
🧩 Entity Example
Train
1
2Train ID: 12951
3Name: Mumbai Rajdhani
4Route: Mumbai -> Delhi
5Classes: [1AC: 20 seats, 2AC: 50 seats, 3AC: 100 seats, Sleeper: 200 seats]Booking
1
2PNR: AB1234
3Train: 12951
4Date: 2025-10-24
5Passengers: [Sahil (28, M), Priya (25, F)]
6Status: Confirmed
7Coach: 3AC
8Seat Numbers: [B4-21, B4-22]🧠 Design Considerations
Concurrency Handling:
Waiting List Handling:
Cancellation Flow:
Extensibility:
🔄 Example Flow
Booking Flow
1
2PNR: AB1234
3Status: Confirmed
4Seats: B4-21, B4-22When Seats are Full
1
2PNR: XY9876
3Status: Waiting (Position 3)Cancellation Flow
🧱 Sample Class Diagram (Conceptual)
1
2+-------------------+
3| Train |
4+-------------------+
5| trainId |
6| name |
7| route |
8| coaches |
9+-------------------+
10
11+-------------------+
12| Seat |
13+-------------------+
14| seatNumber |
15| status |
16| classType |
17+-------------------+
18
19+-------------------+
20| Booking |
21+-------------------+
22| pnr |
23| trainId |
24| passengers |
25| status |
26| seats |
27+-------------------+
28
29+-------------------+
30| BookingService |
31+-------------------+
32| +bookTicket() |
33| +cancelTicket() |
34+-------------------+
35
36+-------------------+
37| WaitingListManager|
38+-------------------+
39| +addToWaiting() |
40| +promoteToConfirm()|
41+-------------------+🚀 Extensions (Optional)
✅ Goal:
Design an object-oriented Railway Ticket Booking System that supports train search, seat availability, booking, cancellation, and waiting list management — ensuring extensibility, concurrency safety, and clean modular design.