The Smart Waitlist Engine
Managing sold-out events is typically a nightmare for organizers. Students beg for tickets, attendees no-show, and manual transfers lead to fraud. UniTix solves this entirely through backend automation.The Trigger: Reaching Capacity
When a Society Admin creates an event, they define acapacity (e.g., 500 tickets).
Every time a ticket is purchased, a Firebase Transaction atomically increments the ticketsSold counter.
When ticketsSold === capacity, the frontend automatically locks ticket sales and swaps the primary CTA button to “Join Waitlist”.
The Queue
Students who join the waitlist are stored in a Firestore subcollection:events/{eventId}/waitlist/{userId}
They are ordered strictly by the joinedAt server timestamp.
The Reallocation Flow
The magic happens when an existing ticket holder realizes they can’t attend and clicks Cancel Ticket.- Transaction Begins: The backend runs an atomic Firebase transaction.
- Decrement Counter: The
ticketsSolddrops from 500 to 499. - Fetch Next in Line: The backend queries the
waitlistsubcollection for the oldest entry. - Grant Reservation: The backend moves that user from the waitlist into a special
ticketReservationsarray on the event document. - Email Notification: The student is automatically emailed: “A spot opened up! You have 24 hours to claim it.”
The 24-Hour Cron Job
What happens if the student misses the email? We cannot let that ticket sit empty forever. UniTix utilizes a scheduled Cron Job (/api/cron/cleanup-waitlist) that runs every single hour.
- It scans all events globally.
- It checks the
reservedAttimestamp of every user in theticketReservationsarray. - If
reservedAtis older than 24 hours, the cron job violently deletes their reservation. - It immediately grants the reservation to the next person on the waitlist.
