This project started from a simple pain point: ticket systems look easy until real users hit them at the same time.
If 500 people try to grab the same seats, naive code breaks. You get:
- double booking
- stale reservations
- weird booking states
- support nightmares
So this backend is built around that reality.
The focus here is not fancy architecture for show. The focus is correctness under pressure.
Main goals:
- no double-sell under concurrency
- temporary hold before payment
- clean expiry and release of abandoned reservations
- clear and predictable booking state transitions
We split booking into two clear steps:
- Reserve: hold tickets for a short window and create a pending booking
- Confirm: finalize reserved tickets and mark booking complete
If someone reserves and disappears, we do not keep inventory blocked forever.
A worker keeps checking expired reservations and does this:
- tickets back to available
- booking marked expired
Under the hood:
- Postgres transactions for consistency
- Redis for short-lived reservation behavior
- background worker for expiry cleanup
Code layout is simple on purpose:
- handlers are thin
- services carry the business flow
- repositories handle DB operations
- Ran 6000 real HTTP booking requests across multiple high-contention scenarios.
- Result: zero double-bookings, zero 5xx, and sold inventory always matched available inventory.
- After adding ticket indexes, hot-path latency improved significantly (example: reserve p95 448ms -> 206ms, confirm p95 368ms -> 174ms in the 1000-user test).