A robust, scalable backend service for an Event Booking platform. This architecture focuses on "immutable fundamentals"—specifically prioritizing strict resource management, concurrency control to prevent race conditions during ticket booking, and decoupled event-driven background processing.
- Runtime & Framework: Node.js, Express.js
- Database & ORM: PostgreSQL (Dockerized), Prisma ORM (v7 Adapter Pattern)
- Architecture: Domain-driven feature modules, Event-driven background tasks
- Role-Based Access Control (RBAC): Strictly namespaced routes isolating
ORGANIZERandCUSTOMERlogic using custom header-based mock authentication. - Concurrency Control (Atomic Transactions): Leverages Prisma
$transactionand atomic decrements at the database level to guarantee ticket integrity and prevent double-booking under heavy load. - Event-Driven Background Jobs: Utilizes Node's native
EventEmitterto detach heavy async processing from the main HTTP thread.- Task 1: Booking Confirmation (Simulated Email)
- Task 2: Event Update Notifications (Simulated broadcast to attendees)
- Dockerized Infrastructure: Containerized PostgreSQL database for isolated, reproducible local development.
- Node.js (v18+)
- Docker Desktop (Running)
- Windows PowerShell
Create a .env file in the root directory:
DATABASE_URL="postgresql://postgres:password123@localhost:5433/event_booking?schema=public"
PORT=3000Open your PowerShell terminal and run the following commands to spin up the database and apply the schema:
# Start the Dockerized PostgreSQL database
docker-compose up -d
# Install dependencies
npm install
# Push the schema and generate the Prisma Client
npx prisma db push
npx prisma generateTo properly observe the background jobs and atomic transactions, follow this split-terminal testing flow.
In your primary PowerShell window, boot up the development server:
npm run devLeave this terminal open and visible so you can watch the console.log outputs trigger from the background jobs.
Because the database enforces strict Foreign Key constraints, we need to create dummy users before we can book events. Open a second PowerShell window in the project root and run this seeding script:
node -r dotenv/config -e "const p = require('./src/config/db'); async function seed(){ await p.user.create({data:{id:'org-1', role:'ORGANIZER'}}); await p.user.create({data:{id:'cust-1', role:'CUSTOMER'}}); console.log('Users seeded!'); } seed();"Use an API client to simulate the user journey. Important: We are using mock authentication. You must include the x-user-id and x-user-role headers in every request.
- POST
http://localhost:3000/api/organizer/events - Headers:
x-user-id:org-1x-user-role:ORGANIZER
- Body:
{ "title": "System Design Masterclass", "description": "Deep dive into scalable backend architectures.", "date": "2026-06-15T10:00:00Z", "totalTickets": 50 }
(Copy the generated id from the response for the next steps).
- POST
http://localhost:3000/api/customer/bookings - Headers:
x-user-id:cust-1x-user-role:CUSTOMER
- Body:
{ "eventId": "<PASTE_EVENT_ID_HERE>", "ticketsCount": 2 }
👉 Check Terminal 1: You will immediately see the background job log:
[BACKGROUND JOB] 📧 Email Action: Sending booking confirmation...
- PUT
http://localhost:3000/api/organizer/events/<PASTE_EVENT_ID_HERE> - Headers:
x-user-id:org-1x-user-role:ORGANIZER
- Body:
{ "title": "System Design Masterclass (Rescheduled!)" }
👉 Check Terminal 1: You will see the notification engine iterate through the attendees:
[BACKGROUND JOB] 🔔 Notification: Alerting Customer cust-1 about updates...