Skip to content
Laviyx Learn

Try

Final-year project

Railway Reservation System with Java and SQL

A ticket booking system for trains with routes, seat availability by date and class, PNR numbers, waiting lists that move up on cancellation, and safe booking when many users try at once.

Intermediate 8–10 weeks 2–4 studentsUpdated

JavaSpring Boot or JDBCMySQL or PostgreSQLHTML or JavaFX front end

The problem

Train booking is a classic system-design problem: thousands of people want the same few seats at the same moment, and every seat must be sold exactly once. This project builds a simplified reservation system with the core ideas of real ones — routes, availability, waiting lists and safe concurrent booking — using your own sample trains and stations.

Features to build

  • Admin adds stations, trains, routes with stop order and distances, and coaches with seat counts per class
  • Search trains between two stations for a date, with availability per class
  • Book up to 6 passengers with name, age and berth preference, and get a unique PNR
  • Fare calculated from distance and class
  • Waiting list when seats run out, with a numbered position
  • Cancellation with a refund rule, automatically giving the freed seat to the first waiting passenger
  • PNR status page and booking history
  • Safe booking when two users try to book the last seat at the same time

Suggested data model

TableKey columns
stationscode (primary key), name, city
trainsnumber, name
route_stopstrain_number, stop_order, station_code, distance_km, departs_at
seatsid, train_number, coach, seat_number, class, berth_type
bookingspnr (unique), user_id, train_number, journey_date, from_code, to_code, status, fare
passengersid, pnr, name, age, seat_id (nullable), waitlist_number (nullable), status

Build plan

  1. 1

    Model routes and seats

    Create the tables and load sample data for a few trains, stations and coaches.

  2. 2

    Search and availability

    For a date and class, count seats not taken by confirmed passengers on that train. Start with whole-journey bookings and add partial journeys as an extension.

  3. 3

    Book safely

    In one transaction, lock the free seats you want with SELECT … FOR UPDATE, assign them, create the booking and commit. If no seats are left, add the passengers to the waiting list.

  4. 4

    Cancel and promote

    When a confirmed passenger cancels, free the seat and, in the same transaction, give it to the passenger with the lowest waiting-list number.

  5. 5

    Test concurrency

    Write a Java test that starts many threads booking the same last seats, and check that no seat is ever sold twice.

Learn these first

Each part of the project is taught in one of these free lessons.

Make it stand out

  • Seats that are free for part of a journey, booked for another part
  • Tatkal-style quota that opens at a set time
  • Chart preparation: final seat list for each coach before departure
  • Load test with many simulated users booking at once

Viva and interview questions

Try to answer each one aloud before you open it.

  • How do you make sure a seat is never sold twice?

    Booking happens inside a transaction that locks the chosen seat rows with SELECT … FOR UPDATE. A second transaction trying the same seats waits until the first commits, then sees them as taken. A unique constraint on (seat_id, journey_date) for confirmed passengers is a second safety net.

  • How is a PNR made unique?

    Generate it from a database sequence or a random value and declare the column UNIQUE, so the database rejects any duplicate. Random-looking PNRs also stop people guessing other passengers' bookings.

  • How does the waiting list move up?

    When a seat is freed, the system picks the waiting passenger with the lowest waitlist number for that train, date and class, assigns the seat and updates the others' positions, all in one transaction.

  • Why test with many threads?

    Concurrency bugs do not show up when one person clicks at a time. Many threads booking at once reproduce the real rush and prove that the locking works.

What to put in your project report

  1. Abstract: the problem, your solution and the result in one paragraph.
  2. Introduction and problem statement: who has the problem and why it matters.
  3. Requirements: the features (functional) and qualities such as speed and security (non-functional).
  4. Design: architecture diagram, database tables or data flow, and screen layouts.
  5. Implementation: the main modules and the most interesting code, explained.
  6. Testing: the test cases you ran, with inputs, expected and actual results.
  7. Results: screenshots or numbers that show the project working.
  8. Conclusion and future scope: what you achieved and what you would add next.

Your college may give its own format. Follow that first, and use this list to check nothing is missing.

All project ideas →