The Challenge: In a standard web app, two users clicking "Buy" at the same time is fairly rare. In a ticket launch, it's guaranteed to happen. This project implements a distributed locking mechanism to prevent race conditions and "double bookings" when thousands of concurrent requests target the same inventory.
- Frontend: React (Vite + TypeScript) with Optimistic UI updates
- Backend: Go (Fiber) for high-performance HTTP & WebSocket handling
- State Management: Redis (for atomic
SET NXlocking and real-time pub/sub) - Persistence: PostgreSQL (for ACID-compliant transaction recording)
- Infrastructure: Docker & Docker Compose
- Real-Time Seat Map: WebSocket integration pushes seat status updates (Held/Sold) to all connected users instantly
- Atomic Locking: Uses Redis Lua scripts to ensure hold/release operations are atomic and race-condition free
- Ephemeral Identity: Client-side UUID generation to simulate unique users without complex auth guardrails
- Performance: Utilizes Redis Pipelining to batch fetch thousands of seat states in a single network roundtrip
Follow these steps to run the system locally.
- Prerequisites:
- Docker Desktop (Running)
- Go (v1.21 or higher)
- Node.js (v18 or higher)
- Start Infrastructure
Create the Redis and PostgreSQL containers.
# From root directory
docker-compose up -d- Start the Backend (Go)
This runs the API server at http://localhost:3000. The application will automatically create the necessary database tables on startup.
cd server
go mod tidy
go run main.goYou should see: ✅ Connected to Redis and ✅ Connected to Postgres and ensured table exists.
- Start the Frontend (React)
This runs the UI at http://localhost:5173.
# Open a new terminal
cd client
npm install
npm run dev- Open the app in Chrome (or any other browser of your choice)
- Open the app in Firefox (an incognito window, or any other browser of your choice)
- Notice that you'll have a different
User: user_xyzID in each window - Click a seat in Chrome (first window)
- Result: Instant update in Firefox (second window, turns grey)
- Try to click the same seat in Firefox (second window)
- Result: "Seat already held by another user" error.