This project is a theater ticket booking system with FastAPI, SQLAlchemy, and Redis. It provides functionality for checking available seats, booking seats, and temporarily reserving seats with an expiry time.
- Check available theaters.
- Check available seats in a theater.
- Book a seat (idempotent operation).
- Temporarily reserve a seat with an expiry time.
- Caching for seat availability. We will cache only those object which are not booked.
- Docker
- Docker Compose
-
Clone the Repository:
git clone [email protected]:pranaybankar/ticketing_system.git
cd theater_booking
-
Build and Run the Docker Containers:
- The data is already feeded in SQLITE DB, if you want to update the data please add it in
app/data/theaters.json
andapp/data/seats.json
before running the below commnads.
docker-compose up --build
- The data is already feeded in SQLITE DB, if you want to update the data please add it in
-
Access the Application:
- The FastAPI application will be available at http://localhost:8000.
-
API Endpoints:
GET /theaters
: Retrieves all theater information.GET /theaters/{theaterId}/seats
: Retrieves the current availability of seats for a specified theater.POST /theaters/{theaterId}/book
: Books a seat for a specified theater.POST /theaters/{theaterId}/reserve
: Temporarily reserves a seat for a specified theater with an expiry time of five minutes.
-
How to use the API Endpoints:
- To try any API click on the
Try it out
button. GET /theaters
: Run this first to retrieves all theatre information. Using this you get to know the Theatreid
andname
.GET /theaters/{theaterId}/seats
: Using the information from the earlier API you can check how many seats are available in the particular theatre. So, you can retrieve the current availability of seats for a specified theatre. So, you will get theid
,seat_number
,is_booked
andtheater_id
.POST /theaters/{theaterId}/reserve
: To temporarily reserves a seat for a specified theatre provide the Theatre id and the seat number from the earlier API. The seat will be reserved for 5 mins to book. If you make a mistake in providing the seat number the API will return the available seat numbers. Note: You need to provide thetheatre_id
as a path parameter andseat_number
as a body payload parameter.POST /theaters/{theaterId}/book
: Now to book your ticket specify the Theatre Id and the seart number to books a seat for the specified theatre. If you make a mistake in providing the seat number the API will return the available seat numbers. Note: You need to provide thetheatre_id
as a path parameter andseat_number
as a body payload parameter.
- To try any API click on the
-
Stopping the Containers:
docker-compose down
- Ensure Docker and Docker Compose are installed on your machine.
- The application uses Sqlite as the database and Redis for caching.
- I have used Swagger UI to interact with the APIs.
- You can update the RESERVATION_TIMEOUT in
docker-compose.yml
file.
This setup ensures your theater ticket booking system is containerized, easy to deploy, and scalable.