Airplane Seat Booking System

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-02

Problem Statement

Design the Low-Level Design (LLD) of an Airplane Seat Booking System that allows passengers to search, select, and book seats on flights operated by different airlines.


The focus should be on object-oriented design, class modeling, and workflow, not large-scale infrastructure, load balancing, or distributed consistency (which would fall under HLD).


🎯 Goal


Design a system that can:


β€’Allow users to search for flights based on source, destination, and date.
β€’Show available flights and seats.
β€’Allow users to book or cancel seats.
β€’Support seat selection, pricing, and payment.
β€’Maintain seat availability and booking records accurately.


βœ… Functional Requirements


1. Flight Search


β€’Users can search flights by:
β€’Source β†’ Destination
β€’Travel Date
β€’Results should show:
β€’Flight number, airline, departure time, arrival time, and seat availability.


2. Seat Selection & Booking


β€’Each flight has a fixed seating layout (e.g., 30 rows Γ— 6 seats per row).
β€’Seats can be of different classes:
β€’Economy
β€’Business
β€’First class
β€’Each seat can be in one of these states:
β€’AVAILABLE, RESERVED, or BOOKED
β€’User can:
β€’View available seats.
β€’Select one or multiple seats.
β€’Proceed to payment.
β€’Once payment succeeds β†’ seat status = BOOKED


3. Booking Management


β€’Generate a booking record (PNR).
β€’Store passenger details, flight info, and seat numbers.
β€’Allow users to:
β€’View past bookings.
β€’Cancel a booking (changes seat status back to AVAILABLE).


4. Payment


β€’User can pay via card, wallet, or UPI.
β€’Payment should have a status:
β€’PENDING β†’ SUCCESS / FAILED
β€’Only successful payments confirm booking.


5. Admin / Airline Management


β€’Admin can:
β€’Add new flights.
β€’Update flight schedules.
β€’Modify seat configurations.
β€’Manage flight cancellations.


βš™οΈ Non-Functional Requirements


β€’Thread-safe seat booking β€” no two users should book the same seat.
β€’Low latency for seat availability checks.
β€’Idempotent booking and cancellation operations.
β€’Extensible to handle multi-leg journeys or connecting flights later.


🧱 Key Classes to Design


ClassResponsibility


User


Represents a customer using the system.


Flight


Represents a flight with details (number, source, destination, schedule).


Seat


Represents an individual seat on a flight (number, class, status).


Aircraft


Represents the aircraft model and seating configuration.


Booking


Represents a confirmed booking for one or more passengers.


Passenger


Represents passenger details within a booking.


Payment


Represents payment info and status.


FlightSearchService


Handles searching for flights.


BookingService


Manages seat reservation, booking confirmation, and cancellation.


PaymentService


Handles payments and updates booking status.


SeatLockService


Prevents concurrent seat bookings (temporary locks).


🧩 Example Class Relationships

1 2User 3 β”œβ”€β”€ id 4 β”œβ”€β”€ name 5 β”œβ”€β”€ email 6 β”œβ”€β”€ List<Booking> 7 8Flight 9 β”œβ”€β”€ flightNumber 10 β”œβ”€β”€ source 11 β”œβ”€β”€ destination 12 β”œβ”€β”€ departureTime 13 β”œβ”€β”€ arrivalTime 14 β”œβ”€β”€ Aircraft aircraft 15 β”œβ”€β”€ List<Seat> 16 17Aircraft 18 β”œβ”€β”€ model 19 β”œβ”€β”€ seatLayout (rows, seatsPerRow) 20 β”œβ”€β”€ List<Seat> 21 22Seat 23 β”œβ”€β”€ seatNumber 24 β”œβ”€β”€ seatClass (Economy / Business / First) 25 β”œβ”€β”€ status (AVAILABLE / RESERVED / BOOKED) 26 β”œβ”€β”€ price 27 28Booking 29 β”œβ”€β”€ bookingId (PNR) 30 β”œβ”€β”€ user 31 β”œβ”€β”€ flight 32 β”œβ”€β”€ List<Passenger> 33 β”œβ”€β”€ List<Seat> 34 β”œβ”€β”€ status (CONFIRMED / CANCELLED) 35 β”œβ”€β”€ payment 36 37Payment 38 β”œβ”€β”€ paymentId 39 β”œβ”€β”€ amount 40 β”œβ”€β”€ status (PENDING / SUCCESS / FAILED) 41 β”œβ”€β”€ method (Card / UPI / Wallet)


πŸ”„ Typical Flow


✈️ Flight Search


1.User enters source, destination, and date.
2.FlightSearchService returns matching flights with seat availability.


πŸ’Ί Booking Flow


1.User selects a flight.
2.Available seats are displayed.
3.User selects seats β†’ system locks them for a short duration.
4.User enters passenger details and proceeds to payment.
5.On payment success β†’ booking is confirmed, seat status changes to BOOKED.
6.If payment fails β†’ seat lock expires, seats revert to AVAILABLE.


❌ Cancellation Flow


1.User requests cancellation.
2.Booking status changes to CANCELLED.
3.Seats are marked AVAILABLE again.
4.Refund (if any) is processed.


πŸ” Concurrency & Data Integrity


β€’Seat booking must be atomic:
β€’Use SeatLockService to prevent double booking.
β€’Once payment is confirmed β†’ persist booking and release lock.
β€’Handle race conditions using synchronized methods or distributed locks (if scaled later).


🧠 Possible Extensions


β€’Add loyalty points or frequent flyer programs.
β€’Add multi-leg or connecting flights.
β€’Add seat upgrades or meal preferences.
β€’Integrate flight status tracking (delays, gate info).


βœ… Final Summary:


Design an Airplane Seat Booking System that enables:


β€’Flight search and seat selection,
β€’Thread-safe booking and payment confirmation,
β€’Booking management and cancellation.


Focus on class design, state transitions, and concurrent seat handling, not on distributed systems or APIs.

Solution

Comments