Learn how to implement a ticket booking system in Node.js that safely handles concurrent seat reservation requests using a seat locking mechanism.
- View available seats
- Lock a seat temporarily (1 minute timeout)
- Confirm a locked seat
- Prevents double booking (race condition safe)
- Automatic lock expiry after 1 minute
- Node.js
- Express.js
.
├── index.js # Main server file
├── package.json # Dependencies
└── README.md # Documentation
-
Clone the repo:
git clone https://github.com/your-username/ticket-booking-system.git cd ticket-booking-system -
Install dependencies:
npm install
-
Start the server:
node index.js
-
Server runs at:
http://localhost:3000
GET http://localhost:3000/seatsResponse:
[
{ "id": 1, "status": "available" },
{ "id": 2, "status": "available" },
{ "id": 3, "status": "available" },
{ "id": 4, "status": "available" }
]POST http://localhost:3000/lock/6Response:
{ "message": "Seat 6 is locked successfully. Confirm within 1 minute" }POST http://localhost:3000/confirm/6Response:
{ "message": "Seat 6 booked successfully" }POST http://localhost:3000/confirm/2Response:
{ "message": "Seat is not locked and cannot be booked" }Here are the sample outputs when running the project:



