A modern event ticketing system built with Laravel, focusing on real-time seat booking and management.
- Soft Deletes: Implemented on key models (Event, Seat, Booking) to maintain data integrity and history
- Relationships:
- One-to-Many between Events and Seats
- One-to-Many between Events and Bookings
- One-to-Many between Users and Bookings
- One-to-One between Seats and Bookings
- Optimizations:
- Indexed foreign keys for faster joins
- Composite indexes for status + expiration checks
- Chunked inserts for large seat generations
- Multi-User Roles:
- Admin users (is_admin flag) for event management
- Regular users for booking tickets
- Route Protection:
- Admin middleware for protecting admin routes
- Custom RedirectIfAdmin middleware for UX
- Session Management:
- Secure session handling with CSRF protection
- Remember-me functionality
- Session-based flash messages
- Status Lifecycle:
- Draft: Initial event creation
- Published: Available for booking
- Cancelled: No longer available
- Seat Map Generation:
- Dynamic grid creation (max 20x20)
- Automatic cleanup of old seats
- Bulk insert optimization
- Validation Rules:
- Maximum dimensions enforcement
- Date and capacity validation
- Price range constraints
- State Machine:
- Seat States: available → reserved → booked
- Booking States: pending → completed/failed
- Payment States: pending → paid/failed/refunded
- Concurrency Control:
- Pessimistic locking for seat operations
- Temporary reservations with TTL
- Transaction isolation for booking operations
- Payment Processing:
- Multiple payment method support
- Secure payment confirmation flow
- Automatic cleanup of abandoned bookings
- Seat Management:
- Live seat status updates (5s polling)
- Immediate booking feedback
- Concurrent booking protection
- User Interface:
- Interactive seat selection
- Real-time availability updates
- Dynamic pricing display
- Scheduled Tasks:
- Expired reservation cleanup (every minute)
- Failed payment handling
- Automatic event status updates
- Maintenance Commands:
- Booking simulation for testing
- Database cleanup utilities
- System health checks
- Business Logic Isolation:
- BookingService for core booking logic
- EventService for event management
- PaymentService for payment processing
- Transaction Management:
- Atomic operations
- Rollback capabilities
- Dead lock prevention
- Unit Tests: Core business logic testing
- Feature Tests: End-to-end testing of key features
- Integration Tests: Testing component interactions
- Concurrency Tests: Simulation of concurrent bookings
The system implements a multi-layered approach to handle concurrent bookings and prevent race conditions:
-
Pessimistic Locking:
- Uses
lockForUpdate()when reserving seats to prevent double bookings - Ensures atomic operations during critical seat status updates
Seat::where('id', $seatId) ->where('status', Seat::STATUS_AVAILABLE) ->lockForUpdate() ->first();
- Uses
-
Transaction Isolation:
- Wraps all booking operations in database transactions
- Prevents phantom reads and non-repeatable reads
DB::transaction(function () { // Seat reservation logic });
-
Temporary Reservation System:
- Time-limited seat reservation (5 minutes)
- Automatic cleanup of expired reservations via scheduled command
- State machine for seat status: available → reserved → booked
-
Scheduled Cleanup:
- Artisan command
seats:cleanup-expiredruns periodically - Releases expired seat reservations
- Updates associated booking statuses
- Artisan command
- Livewire Polling:
- Automatic seat map refresh every 5 seconds
- Immediate UI feedback for user actions
- Optimistic updates with rollback on failure
- Graceful Degradation:
- Comprehensive error catching and logging
- User-friendly error messages
- Automatic reservation cleanup
-
Concurrent Booking Tests:
# Simulate concurrent bookings php artisan booking:simulate {seatId} --users=100 -
Test Coverage:
- Unit tests for booking service
- Feature tests for concurrent scenarios
- Integration tests for booking flow
-
Real-time Updates:
- Implement WebSocket for instant updates
- Replace polling with push notifications
-
Rate Limiting:
- Add rate limiting middleware
- Configure booking attempt thresholds
-
Advanced Monitoring:
- Implement deadlock detection
- Add circuit breaker for external services
- Enhanced logging and monitoring
-
Why Livewire?
- Reduces JavaScript complexity
- Real-time reactivity without building an API
- Seamless integration with Laravel
-
Why Soft Deletes?
- Maintain booking history
- Enable data recovery
- Support for analytics and reporting
-
Why Custom Admin Redirection?
- Better user experience for admin users
- Clear separation between admin and user interfaces
- Simplified navigation flow
-
Why 20x20 Seat Limit?
- Optimal performance for real-time updates
- Reasonable limit for most venues
- Prevents potential scaling issues
-
Scalability Improvements
- Queue system for high-traffic periods
- Distributed caching for seat status
- Horizontal scaling capabilities
-
Feature Enhancements
- Multiple seating categories
- Season pass functionality
- Waiting list system
- Multi-language support
-
Technical Debt Management
- Regular dependency updates
- Code refactoring plan
- Performance monitoring implementation
- Event Management (CRUD operations)
- Interactive Seat Map Display
- Concurrent Seat Booking System
- Admin Panel
- High Concurrency Safety
- Backend Framework: Laravel 12.0
- Frontend Framework: Livewire 3.6
- UI Components: Livewire Flux 2.1
- CSS Framework: TailwindCSS 3.x
- JavaScript: AlpineJS 3.x
- Database: MySQL
- Cache: Redis (for session and cache)
{
"php": "^8.2",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1",
"livewire/flux": "^2.1.1",
"livewire/livewire": "^3.6",
"livewire/volt": "^1.7.0"
}-
Clone the repository:
git clone git@github.com:blessingk/stagepass.git cd stagepass -
Install PHP dependencies:
composer install
-
Install Node dependencies:
npm install
-
Copy .env.example to .env and configure your database:
cp .env.example .env
-
Generate application key:
php artisan key:generate
-
Run migrations:
php artisan migrate --seed
-
Build assets:
npm run dev
-
Start the server:
php artisan serve
-
Start the queue worker (in a separate terminal):
php artisan queue:work
-
Schedule the cleanup command (in a separate terminal):
php artisan schedule:work
Run the test suite:
php artisan testTo simulate concurrent booking attempts:
php artisan booking:simulate {seatId} --users=100This command simulates multiple users attempting to book the same seat simultaneously.
- id
- name
- description
- date
- venue
- rows
- columns
- status (draft, published, cancelled)
- created_at
- updated_at
- deleted_at
- id
- event_id
- row
- column
- status (available, reserved, booked)
- reservation_expires_at
- created_at
- updated_at
- deleted_at
- id
- user_id
- event_id
- seat_id
- status (pending, confirmed, cancelled)
- total_amount
- payment_status
- payment_method
- created_at
- updated_at
- deleted_at
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE.md file for details.