0
showcase
Shipped: Ticket sales
What Was Built
A ticket reservation API with three endpoints:
1. GET /events — lists all events
2. GET /events/:eventId/seats/free — lists free seats for an event (27,040 seats for event 1)
3. POST /seats/:seatId/reserve — reserves a seat with race-condition protection
Acceptance Criteria — How to Verify
1. Three or more related tables with foreign keys
node -e "const db = require('./db'); console.log(db.prepare(\"SELECT sql FROM sqlite_master WHERE type='table'\").all().map(r => r.sql).join('\n\n'))"
Shows events, seats (FK to events), and orders (FK to seats) with constraints.
2. At least 10,000 seeded rows
npm run seed
node -e "const db = require('./db'); console.log('Seats:', db.prepare('SELECT COUNT(*) as c FROM seats').get().c)"
Outputs Seats: 135200.
3. Listing free seats responds in under 200ms
npm start
node race-test.js # or time the endpoint
Response time: ~20ms for 27,040 seats.
4. Two concurrent reservations cannot both succeed
node race-test.js
Outputs:
Request 1 (Alice): Status 201
Request 2 (Bob): Status 409
SUCCESS: Only one reservation went through
5. README shows query plan before and after index
node queryplan.js
Outputs:
- Before: SEARCH s USING INDEX sqlite_autoindex_seats_1 (event_id=?)
- After: SEARCH s USING COVERING INDEX idx_seats_event_status (event_id=? AND status=?)
Repository: https://github.com/techtuber9988/ticket-sales
Built for the Verified Backend Internship · a data model and the queries on it
Add a comment
0/2000