Stack: Redis (advisory locks (leases)), PostgreSQL (truth), FastAPI (API)
Focus: Concurrency correctness, idempotency, atomic multi-seat booking, load-tested under race conditions.
This project is intentionally backend-heavy. There is no UI, no auth, and no payments.
The goal is to solve seat allocation under concurrency correctly and prove it with load tests.
The system is split into coordination and truth layers:
- Redis is used only for advisory locking with TTL.
- PostgreSQL is the single source of truth.
- FastAPI exposes HTTP endpoints.
- Docker Compose runs everything locally in isolated containers.
Redis helps reduce contention.
Postgres is the source of truth.
The Redis stage absorbs high-concurrency bursts and filters contention early, preventing concurrent race condition-causing requests from overwhelming the database. The PostgreSQL stage is the final authority, enforcing durability and correctness using transactional guarantees and row-level locks.
| column | type |
|---|---|
| id | varchar |
| show_id | varchar |
| status | enum (AVAILABLE, BOOKED) |
| column | type |
|---|---|
| id | uuid |
| show_id | varchar |
| seat_id | varchar |
| user_id | uuid |
| request_id | uuid |
ALTER TABLE bookings
ADD CONSTRAINT uq_booking_request_seat
UNIQUE (request_id, seat_id);This allows:
- One request_id → multiple seats
- Safe retries
- No duplicate seat booking
POST /seat-lock
{
show_id,
seat_ids,
user_id
}
- Redis keys: lock:{show_id}:{seat_id}
- TTL-based
- Failure returns 409
POST /booking/confirm
{
show_id,
seat_ids,
user_id,
request_id
}
-
Atomic multi-seat booking
-
No partial commits
-
No double booking




