Skip to content

ivfrost/spring-ticketing-microservices

Repository files navigation

Spring Ticketing (WIP)

A high-performance, event-driven distributed system for event management (as in events that people attend) and ticket processing built with Java 21 and Spring Boot 4.0.1.

Project Workflow

  • API Gateway: Acts as the single entry point. It handles routing to different services and manages security.
  • Inventory Service: Acts as the source of truth for event and venue data. It offers an endpoint to update event available capacity.
  • Booking Service: Receives the initial user request. It does a quick check to see if the event exists before passing the task to the next service via Kafka.
  • Order Service: It listens for messages from Kafka and communicates with the Inventory Service to finalize the event available capacity.

Tech Stack

Web & Security

  • Spring Cloud Gateway: Manages all incoming traffic and directs it to the right service.
  • Spring Security: Protects the application (OAuth2/JWT ready).
  • Keycloak: For authentication and authorization.

Data & Persistence

  • Spring Data JPA: ORM layer (Hibernate) for database interactions.
  • MySQL 8.0: Relational database for persistent storage.
  • Flyway: Handles database migrations and versioning.

Messaging

  • Apache Kafka (KRaft mode): The event bus used for communication between services.

Reliability & DevOps

  • Resilience4j: Provides Circuit Breakers for system stability.
  • Spring Actuator: Monitors application health checks.
  • Docker & Compose: Multi-stage, layered builds for optimized deployment.
  • SonarQube: Used for maintaining code quality.

Fast Deployment with Docker

This project uses Multi-stage Docker Builds to optimize deployment speed and image sizes. By splitting the Spring Boot application into layers, the system only needs to rebuild the code you actually changed. It does not need to re-download or re-process heavy libraries and dependencies every time, making builds significantly faster.


Quick Start

Prerequisites

  • Docker & Docker Compose
  • JDK 21 (only needed for local development)

Running the System

  1. Clone the repository:
git clone https://github.com/ivfrost/spring-ticketing-microservices.git
cd spring-ticketing-microservices
cp .env.example .env
  1. Spin up the infrastructure and services:
docker-compose up -d
  1. Test the API Endpoints:

Step 1: Access Keycloak

  • URL: http://localhost:KEYCLOAK_PORT_EXT
  • User: KC_BOOTSTRAP_ADMIN_USERNAME
  • Pass: KC_BOOTSTRAP_ADMIN_PASSWORD
  • Note: The ticketing-security realm is automatically imported on startup.

Step 2: Create a Test User

  • Select the ticketing-security realm from the top-left menu.
  • Go to Users -> Add user to create your local test account.
  • In the Credentials tab, set a password and turn Temporary to Off.

Step 3: API Gateway Swagger UI

  • URL: http://localhost:API_GATEWAY_PORT/swagger-ui.html

  • Click Authorize and enter the following details:

    • Client ID: ticketing-client-id
    • Client Secret: the secret displayed in the Keycloak admin console under Clients -> ticketing-client-id -> Credentials tab.
  • You can now test the protected endpoints:

    • Inventory: http://localhost:API_GATEWAY_PORT/api/v1/inventory
    • Bookings: http://localhost:API_GATEWAY_PORT/api/v1/bookings
  • Alternatively, you can use Postman to test the endpoints via OAuth2 authentication.

Future Improvements

  • Use SAGA pattern to ensure data consistency across services.
  • Use HashiCorp Vault for managing secrets.

About

A high-performance, event-driven distributed system for event management (as in events that people attend) and ticket processing built with Java 21 and Spring Boot 4.0.1.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors