Skip to content

tokgozkerem/TicketStorm-API

Repository files navigation

TicketStorm API

A high-concurrency event ticketing backend built with Django, focused on data integrity and specialized concurrency control.

Overview

The primary challenge of this system is managing high-volume, simultaneous booking requests for limited inventory. This project implements a robust solution to the race condition problem using database-level locking and asynchronous processing.

Technical Implementation

Concurrency and Data Integrity

  • Row-Level Locking: Uses PostgreSQL SELECT FOR UPDATE within atomic transactions to prevent double-booking. This ensures that only one request can modify a specific seat status at any given millisecond.
  • Idempotency: Implementation of unique idempotency keys to prevent duplicate transactions caused by network retries or client-side double-submits.
  • Database Constraints: Utilization of UniqueConstraint and CheckConstraint at the schema level as a final line of defense for data consistency.

Asynchronous Pipeline

  • Task Offloading: Heavy operations such as ticket PDF generation and email notifications are handled by Celery workers via a Redis broker.
  • Inventory Management: Automated cleanup of expired "Pending" reservations through periodic Celery tasks, ensuring seats return to the available pool if payment is not confirmed within the TTL (Time-To-Live).

System Architecture

  • Backend: Python 3.12 / Django 5.0 / Django REST Framework
  • Database: PostgreSQL 16
  • Task Queue: Redis 7 / Celery 5.4
  • Infrastructure: Docker / Docker Compose

Performance Metrics

A load test was conducted simulating 10 concurrent requests targeting a single available seat.

Metric Value
Concurrent Requests 10
Available Inventory 1
Success Rate 10% (1/10)
Collision Rate 0%
Average Latency 125ms

Setup and Usage

  1. Environment Setup:

    docker-compose up -d
  2. Initialize Database:

    docker-compose exec web python manage.py makemigrations
    docker-compose exec web python manage.py migrate
    docker-compose exec web python manage.py seed_data
  3. Verify Concurrency Logic: A simulation script is provided to demonstrate the locking mechanism under load:

    python3 demo_race.py
  4. API Documentation: The OpenAPI schema is available at /api/docs/ (Swagger UI) or /api/redoc/ once the server is running.

Engineering Focus

This project serves as a demonstration of handling:

  • Race conditions in distributed systems.
  • Pessimistic concurrency control.
  • Background job processing and task scheduling.
  • Containerized multi-service architecture.

About

High-concurrency event ticketing backend (Django + PostgreSQL) showcasing row-level locking, idempotent checkout, TTL-based reservations, and Celery background jobs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages