Skip to content

KartikPawade/Movie-Ticket-Booking-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

118 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation


MovieNow Booking System

A backend-centric movie ticket booking system โ€” handles concurrent seat reservations, async email notifications, Redis-based caching, and fully automated deployments on AWS EKS via CI/CD pipelines.




โœจ Key Features

Feature Description
๐ŸŽŸ๏ธ Concurrent Ticket Booking Redis-based seat reservation locks (6 min TTL) prevent double-booking across concurrent requests
๐Ÿ“ง Async Email Notifications RabbitMQ-powered email service with concurrent workers โ€” checkout API returns instantly
๐Ÿ™๏ธ Theater & Movie Listings Query theaters and movies by city with optimized, cached responses
โšก Redis Caching Frequently accessed, low-write endpoints cached in Redis to reduce DB load
๐Ÿณ Multi-Stage Docker Builds Minimized image size for faster deployments and reduced CI/CD pipeline duration
โ˜ธ๏ธ AWS EKS Deployment Kubernetes StatefulSets for PostgreSQL and RabbitMQ ensure data persistence on EKS
๐Ÿ”„ CI/CD Pipeline Fully automated deployments to AWS EKS via GitHub Actions
๐Ÿ’พ Storage Persistence StatefulSet objects for PostgreSQL and RabbitMQ prevent data loss across pod restarts

๐Ÿ—๏ธ System Architecture

                                ๐Ÿ‘ค User
                                   โ”‚
                                   โ–ผ
                          โšก Spring Boot API
                         /                  \
               Browse / Search          Checkout / Book
                      /                          \
                     โ–ผ                            โ–ผ
            ๐ŸŽฌ Movie & Theater              ๐Ÿ” Seat Reservation
              Listings API                       โ”‚
                     โ”‚                           โ–ผ
                     โ–ผ                   ๐Ÿ”ด Redis Lock
              โšก Redis Cache             (6 min TTL per seat)
         (low-write endpoints)                   โ”‚
                                                 โ–ผ
                                        ๐Ÿ˜ PostgreSQL
                                      (Confirm Booking)
                                                 โ”‚
                                                 โ–ผ
                                       ๐Ÿ“จ RabbitMQ Queue
                                                 โ”‚
                                                 โ–ผ
                                    ๐Ÿ“ง Async Email Workers
                                  (Booking Confirmation Email)

๐Ÿ”ด Concurrent Booking โ€” How It Works

The core challenge: two users booking the same seat at the same time.

Solution: Redis TTL-based seat lock

User A requests Seat 12A
       โ”‚
       โ–ผ
SET seat:12A:lock "userA" EX 360   โ† Redis lock (6 min TTL)
       โ”‚
  Lock acquired?
  /           \
YES             NO
 โ”‚               โ”‚
 โ–ผ               โ–ผ
Proceed      Return "Seat
to checkout  unavailable"
       โ”‚
       โ–ผ
Payment confirmed โ†’ Write to PostgreSQL โ†’ Release lock
       โ”‚
       โ–ผ
Push to RabbitMQ โ†’ Email worker โ†’ Send confirmation

If the user abandons checkout, the Redis lock expires automatically after 6 minutes, freeing the seat for others โ€” no manual cleanup required.


๐Ÿ“ง Async Email Service

Booking confirmation emails are fully decoupled from the checkout flow via RabbitMQ.

POST /checkout
      โ”‚
      โ–ผ
Confirm booking in DB
      โ”‚
      โ–ผ
Publish message to RabbitMQ โ”€โ”€โ†’ Return 200 immediately to user
      โ”‚
      โ–ผ (async)
Email Worker (concurrent consumers)
      โ”‚
      โ–ผ
Send confirmation email to user

Why this matters: The checkout API response time is not blocked by email delivery. Even if the email service is slow or temporarily down, the booking is confirmed and the message stays in the queue.


๐Ÿ› ๏ธ Tech Stack

Layer Technology
API Spring Boot ยท REST
Concurrency Redis (TTL-based seat locks)
Caching Redis Cache
Async Messaging RabbitMQ
Database PostgreSQL
Containerization Docker (Multi-Stage Builds)
Orchestration Kubernetes (AWS EKS)
Persistence Kubernetes StatefulSets
CI/CD GitHub Actions
Cloud AWS EKS

๐Ÿ” API Overview

Movies & Theaters

Method Endpoint Description
GET /cities List all available cities
GET /cities/{cityId}/theaters Get theaters in a city
GET /theaters/{theaterId}/movies Get movies showing at a theater
GET /movies/{movieId}/shows Get show timings for a movie

Booking

Method Endpoint Description
POST /shows/{showId}/reserve Reserve seats (Redis lock, 6 min TTL)
POST /bookings/checkout Confirm booking + trigger async email
GET /bookings/{bookingId} Get booking details
DELETE /bookings/{bookingId} Cancel booking + release seat lock

โ˜ธ๏ธ Kubernetes Deployment

PostgreSQL and RabbitMQ are deployed as StatefulSets inside the same AWS EKS cluster to ensure:

  • Stable network identity โ€” pods get consistent DNS names
  • Persistent storage โ€” data survives pod restarts via PersistentVolumeClaims
  • Ordered deployment โ€” guaranteed startup sequence
AWS EKS Cluster
โ”œโ”€โ”€ Deployment: movieNow-api          (Spring Boot โ€” scalable, stateless)
โ”œโ”€โ”€ StatefulSet: postgresql           (persistent volume for booking data)
โ”œโ”€โ”€ StatefulSet: rabbitmq             (persistent volume for message queue)
โ””โ”€โ”€ CI/CD: GitHub Actions             (auto-deploy on push to main)

๐Ÿ”„ CI/CD Pipeline

Push to main
      โ”‚
      โ–ผ
GitHub Actions triggered
      โ”‚
      โ”œโ”€โ”€ Build multi-stage Docker image
      โ”œโ”€โ”€ Push to container registry
      โ””โ”€โ”€ Deploy to AWS EKS
              โ”‚
              โ–ผ
        Rolling update
      (zero downtime deployment)

Multi-stage Docker builds keep the final image lean by separating the build environment from the runtime environment โ€” resulting in significantly smaller image sizes and faster pull times during deployment.


๐Ÿ—„๏ธ Database Schema

cities
 โ””โ”€โ”€ theaters
      โ””โ”€โ”€ movies
           โ””โ”€โ”€ shows
                โ””โ”€โ”€ bookings
                     โ””โ”€โ”€ booked_seats
users
 โ””โ”€โ”€ bookings  (userId ยท showId ยท status ยท createdAt)
      โ””โ”€โ”€ booked_seats  (seatId ยท bookingId)

shows  (movieId ยท theaterId ยท showTime ยท totalSeats ยท availableSeats)
seats  (showId ยท seatNumber ยท type ยท price)

User Flow

User Flow Diagram

Database Schema

Database Schema


๐Ÿš€ Setup & Running

Prerequisites

  • Java 17+
  • Docker
  • kubectl + AWS CLI (for EKS deployment)

1. Start Infrastructure

docker compose up -d   # Starts PostgreSQL + RabbitMQ + Redis

2. Run the Application

./mvnw spring-boot:run
# API available at http://localhost:8080

3. Deploy to AWS EKS

# Apply Kubernetes manifests
kubectl apply -f k8s/postgresql-statefulset.yaml
kubectl apply -f k8s/rabbitmq-statefulset.yaml
kubectl apply -f k8s/movieNow-deployment.yaml

Or simply push to main โ€” GitHub Actions handles the rest.


๐Ÿ”‘ Environment Variables

# Database
SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/movienow
SPRING_DATASOURCE_USERNAME=postgres
SPRING_DATASOURCE_PASSWORD=...

# Redis
SPRING_REDIS_HOST=localhost
SPRING_REDIS_PORT=6379

# RabbitMQ
SPRING_RABBITMQ_HOST=localhost
SPRING_RABBITMQ_PORT=5672
SPRING_RABBITMQ_USERNAME=guest
SPRING_RABBITMQ_PASSWORD=guest

# Email
MAIL_HOST=smtp.gmail.com
MAIL_USERNAME=...
MAIL_PASSWORD=...

๐Ÿ’ก What Makes This Stand Out

  • Race condition handling without DB locks โ€” Redis TTL-based seat reservation is lighter and faster than pessimistic DB locking, and self-heals on abandoned checkouts.
  • Checkout API latency is email-independent โ€” RabbitMQ decoupling means a slow email provider never degrades the booking experience.
  • Production-grade infra โ€” StatefulSets, PVCs, rolling deployments, and CI/CD from day one, not bolted on later.
  • Multi-stage Docker โ€” build artifacts stay out of the final image, keeping it lean for faster EKS pull times.

๐Ÿ”ฎ Upcoming Features

  • Full API Caching โ€” Extend Redis caching to remaining read-heavy endpoints while maintaining consistency
  • API Documentation โ€” Swagger/OpenAPI integration for full endpoint documentation
  • Bean Validation โ€” Spring Validation annotations on all request objects for consistent input integrity

Built with Spring Boot ยท Redis ยท RabbitMQ ยท PostgreSQL ยท Docker ยท AWS EKS ยท GitHub Actions

About

Backend for app to book and track movie-tickets for upcoming movies

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors