🚀 A production-ready backend system designed to handle high-concurrency scenarios like flash sales where thousands of users compete for limited inventory simultaneously.
🎯 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.
- 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
⚡ 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.
- 🚀 Async Processing: Immediate
202 Acceptedresponses 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
-
📥 Clone & Install:
git clone <repository-url> cd tickets-hive npm install
-
▶️ Start Services:npm run docker:dev
-
📚 View Documentation:
npm run docs
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 documentationtickets-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
- 🔐 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.
✅ 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
MIT
Built as a demonstration of scalable backend architecture patterns for high-concurrency scenarios.