Design of airline reservation system with graph-based modeling

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-11-13

Problem Statement

Design a flight booking and reservation system where airports and flights are modeled as a graph. The focus is on object-oriented design, graph modeling, path finding, and modular system components.


✅ Functional Requirements


1.Flight & Airport Management
•Store airports: airportCode, name, location.
•Store flights: flightNumber, sourceAirport, destinationAirport, departureTime, arrivalTime, capacity.
•Each flight acts as a directed edge between two airport nodes.
2.Passenger Management
•Store passenger details: passengerId, name, contactInfo.
•Allow booking, cancellation, and retrieval of booking information.
3.Reservation & Booking
•Book a seat on a flight → reduce available seats.
•Cancel a booking → increase available seats.
•Support multi-leg flights by finding paths in the airport-flight graph.
4.Search & Routing
•Find available flights between source and destination airports.
•Support shortest path or cheapest path search using graph traversal algorithms (e.g., BFS, Dijkstra).
5.Optional Features
•Track flight status (delayed, cancelled).
•Support frequent flyer programs and seat classes.
•Real-time seat availability updates.


🔐 Constraints & Assumptions


•Focus is on LLD, graph modeling, and modular components, not payment or UI integration.
•Flight capacity is limited; booking must not exceed capacity.
•Assume unique flight numbers and airport codes.


🧱 Key Components & Classes


1.Airport Class
1 2class Airport { 3private: 4 string code; // e.g., JFK, LHR 5 string name; 6 string location; 7 vector<Flight*> outgoingFlights; // edges in graph 8public: 9 void addFlight(Flight* flight); 10 vector<Flight*> getOutgoingFlights(); 11};
1.Flight Class
1 2class Flight { 3private: 4 string flightNumber; 5 Airport* source; 6 Airport* destination; 7 DateTime departureTime; 8 DateTime arrivalTime; 9 int capacity; 10 int seatsAvailable; 11public: 12 bool bookSeat(); 13 void cancelSeat(); 14 bool isAvailable(); 15};
1.Passenger Class
1 2class Passenger { 3private: 4 string passengerId; 5 string name; 6 string contactInfo; 7 vector<Flight*> bookings; 8public: 9 void bookFlight(Flight* flight); 10 void cancelFlight(Flight* flight); 11};
1.ReservationManager Class
1 2class ReservationManager { 3private: 4 unordered_map<string, Passenger*> passengers; 5 unordered_map<string, Airport*> airports; 6 unordered_map<string, Flight*> flights; 7public: 8 Flight* searchFlight(string sourceCode, string destCode); 9 vector<Flight*> findPath(string sourceCode, string destCode); // graph-based search 10 bool bookFlight(string passengerId, string flightNumber); 11 bool cancelBooking(string passengerId, string flightNumber); 12};
1.Graph Utilities (Optional)
•Algorithms for shortest path, cheapest path, or minimum connections.


🔄 Example Workflow


1.System loads airports and flights → builds graph with airports as nodes and flights as edges.
2.Passenger searches for flights from JFK → LHR → ReservationManager.findPath() returns paths.
3.Passenger books a flight → bookSeat() reduces available seats, booking recorded in Passenger.
4.Cancellation → cancelSeat() increments availability.
5.Optional: compute shortest travel time path using graph algorithms.


🧪 Expected Deliverables


•Class diagram showing Airport, Flight, Passenger, and ReservationManager.
•Implementation of booking, cancellation, and graph-based flight search.
•Test cases:
•Single-leg flight booking and cancellation
•Multi-leg flight search
•Seat availability enforcement
•Path finding correctness


💡 Discussion Points


•Graph representation: adjacency list vs adjacency matrix.
•Pathfinding algorithms for shortest or cheapest routes.
•Handling concurrent bookings and seat updates.
•Extensibility for real-time flight status, multiple classes, or pricing tiers.


Solution

Comments