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.
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
Build plan
- 1
Model routes and seats
Create the tables and load sample data for a few trains, stations and coaches.
- 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
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
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
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.
- Java Collections Framework Overview: List, Set, Map and Queue
- Java Exceptions: try, catch, finally, throw, Checked vs Unchecked
- Java Threads and Concurrency: Thread, ExecutorService, synchronized, Atomic and Virtual Threads
- Java Streams API: filter, map, reduce, collect and groupingBy
- SQL CREATE TABLE: Define a New Table Step by Step
- SQL Constraints: PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT
- SQL Subqueries Explained: Queries Inside Queries
- SQL Indexes Explained: Make Queries Fast (and When Not To)
- SQL Transactions: BEGIN, COMMIT, ROLLBACK and ACID
- SQL Stored Procedures: Reusable Logic Inside the Database
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
- Abstract: the problem, your solution and the result in one paragraph.
- Introduction and problem statement: who has the problem and why it matters.
- Requirements: the features (functional) and qualities such as speed and security (non-functional).
- Design: architecture diagram, database tables or data flow, and screen layouts.
- Implementation: the main modules and the most interesting code, explained.
- Testing: the test cases you ran, with inputs, expected and actual results.
- Results: screenshots or numbers that show the project working.
- 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.
More project ideas
- Student Result Management System in PythonMini project
- Library Management System in JavaMini project
- Blood Bank Management SystemFinal-year project