Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🎟️ Concurrent Ticket Booking System with Seat Locking and Confirmation

📌 Objective

Learn how to implement a ticket booking system in Node.js that safely handles concurrent seat reservation requests using a seat locking mechanism.

🚀 Features

  • 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

🛠️ Tech Stack

  • Node.js
  • Express.js

📂 Project Structure

.
├── index.js        # Main server file
├── package.json    # Dependencies
└── README.md       # Documentation

▶️ Setup Instructions

  1. Clone the repo:

    git clone https://github.com/your-username/ticket-booking-system.git
    cd ticket-booking-system
  2. Install dependencies:

    npm install
  3. Start the server:

    node index.js
  4. Server runs at:

    http://localhost:3000
    

📡 API Endpoints

1️⃣ Get All Seats

GET http://localhost:3000/seats

Response:

[
  { "id": 1, "status": "available" },
  { "id": 2, "status": "available" },
  { "id": 3, "status": "available" },
  { "id": 4, "status": "available" }
]

2️⃣ Lock a Seat

POST http://localhost:3000/lock/6

Response:

{ "message": "Seat 6 is locked successfully. Confirm within 1 minute" }

3️⃣ Confirm Booking

POST http://localhost:3000/confirm/6

Response:

{ "message": "Seat 6 booked successfully" }

4️⃣ Error: Confirm Without Lock

POST http://localhost:3000/confirm/2

Response:

{ "message": "Seat is not locked and cannot be booked" }

📸 Output

Here are the sample outputs when running the project:

Output 1
Output 2
Output 3
Output 4

About

A Node.js and Express.js based ticket booking system with seat locking. Seats can be locked temporarily (1 minute) before confirmation to prevent double booking. Ensures safe concurrent booking by handling race conditions with in-memory seat management.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages