Skip to content

High-concurrency event booking system built to handle thousands of simultaneous users competing for limited inventory.

Notifications You must be signed in to change notification settings

segmentationfaulter/tickets_hive

Repository files navigation

🎫 TicketsHive - High-Concurrency Event Booking System

🚀 A production-ready backend system designed to handle high-concurrency scenarios like flash sales where thousands of users compete for limited inventory simultaneously.

📖 Overview

🎯 TicketsHive solves the challenge of building a system that can handle extreme concurrency scenarios where thousands of users simultaneously attempt to purchase from limited ticket inventory without any overbookings. The solution uses an async queue-based architecture with optimistic locking that provides sub-100ms API response times, 100% data integrity, and horizontal scalability.

🛠️ Tech Stack

  • Runtime: Node.js 24+ with native TypeScript support
  • Framework: Express.js
  • Database: PostgreSQL with ACID compliance
  • Queue System: BullMQ with Redis backend
  • Build System: Turborepo monorepo
  • Authentication: JWT
  • Containerization: Docker & Docker Compose
  • Type Safety: TypeScript with Zod validation

🏗️ Architecture

⚡ The system uses an async queue-based architecture to decouple request acceptance from processing:

┌─────────────┐    POST /bookings     ┌─────────────────┐
│             │ ────────────────────► │                 │
│   Client    │                       │  API Service    │
│             │                       │  (/apps/api)    │
└─────────────┘                       └────────┬────────┘
                                               │
                                               │ Validate & Create Job
                                               │ Return 202 + jobId
                                               ▼
                                       ┌─────────────────┐
                                       │   Redis/BullMQ  │
                                       │   - Job Queue   │
                                       └────────┬────────┘
                                               │
                                               │ Worker Pulls Job
                                               ▼
                                       ┌─────────────────┐
                                       │ Worker Service  │
                                       │ (/apps/worker)  │
                                       └────────┬────────┘
                                               │
                                               │ Optimistic Locking
                                               │ Database Update
                                               ▼
                                       ┌─────────────────┐
                                       │ PostgreSQL      │
                                       └─────────────────┘

🔑 Key Components:

  • API Service: Accepts booking requests and returns immediately with job ID
  • Worker Service: Processes booking jobs with optimistic locking
  • Redis/BullMQ: Job queue for asynchronous processing
  • PostgreSQL: Primary data store with version-based optimistic locking 🗄️

✅ This architecture ensures immediate feedback to users while maintaining data integrity under extreme load.

✨ Key Features

  • 🚀 Async Processing: Immediate 202 Accepted responses with job tracking
  • 🔒 Optimistic Locking: Version-based concurrency control without database locks
  • 📈 Horizontal Scalability: Independent scaling of API and worker services
  • 📡 Status Polling: Job status tracking via polling endpoints, SSE enhancement coming
  • 🛡️ Type Safety: Full TypeScript coverage with runtime validation
  • ⚠️ Error Handling: Comprehensive error categorization and user-friendly messages

🚀 Quick Start

  1. 📥 Clone & Install:

    git clone <repository-url>
    cd tickets-hive
    npm install
  2. ▶️ Start Services:

    npm run docker:dev
  3. 📚 View Documentation:

    npm run docs

🔧 Development Commands

npm run docker:dev    # 🐳 Start all services
npm run docker:logs   # 📋 View service logs
npm run docker:stop   # ⏹️ Stop services
npm run build         # 🔍 Type-check all packages
npm run docs          # 📖 Preview API documentation

📁 Project Structure

tickets-hive/
├── apps/
│   ├── api/          # 🌐 Express API service
│   └── worker/       # ⚙️ Background job processor
├── packages/
│   ├── database/     # 🗄️ PostgreSQL client
│   ├── types/        # 📝 Shared TypeScript types
│   └── lib/          # 🔧 Utilities and configuration
└── docker-compose.yml

🌐 API Endpoints

  • 🔐 Authentication: Register, login with JWT
  • 🎭 Events: Create, list, and view event details
  • 🎫 Bookings: Create booking jobs, check status, cancel bookings

📖 For complete API documentation, see the OpenAPI specification or run npm run docs.

📊 Current Status

✅ The core booking system is fully functional with async queue-based processing and optimistic locking. The system handles high-concurrency scenarios with guaranteed data integrity and sub-100ms response times.

🚀 Planned Enhancements:

  • 🔔 Real-time status updates via Server-Sent Events
  • 🛡️ Production-grade rate limiting and circuit breakers
  • 📊 Enhanced monitoring and observability
  • 📈 Separate dashboard service for queue management

📄 License

MIT


Built as a demonstration of scalable backend architecture patterns for high-concurrency scenarios.

About

High-concurrency event booking system built to handle thousands of simultaneous users competing for limited inventory.

Resources

Stars

Watchers

Forks