Backend hosted at https://www.ticketeer.ml/api/v1
Frontend hosted at www.ticketeer.ml
- [Main] Learn and familiarize with Go programming language
- [Main] Concurrency in practice (with and w/o database features help)
- Pinpoint possible limitations in each implementation phase’s design
- Design for optimal performance (where to store data and in what form it should be stored)
- User System Functionalities
- Register / Sign-up
- Login
- User Roles
- Admin
- Event Organizer
- Customer
- Event Management Functionalities
- Create/View/Edit/Delete Event
- Required Properties
- Event Name
- Ticket Quota/Limit
- Admins can view and delete all events in the system
- Event Organizers can create/view/edit/delete their own events
- Customers can view all events and are able to make reservation(s) on any event. (Customers can reserve more than 1 ticket per request.)
- Tickets can only be sold if there’s quota left or have not reached their limits
- Customers are able to cancel their reservations
- Event Organizers can see total ticket reserved / remaining ticket quota
Design and implement a (backend) service with HTTP APIs serving the above mentioned functionalities using Go programming language
Phase 2 - Use persistence (relational database) (e.g. PostgreSQL) to store quota (naive implementation)
- Go 1.13 or later
-
Start PostgreSQL
docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=postgres --name ticket_reservation_postgres postgres:12-alpine
-
Create database
docker exec -i ticket_reservation_postgres psql -U postgres -c "drop database if exists ticket_reservation" && docker exec -i ticket_reservation_postgres psql -U postgres -c "create database ticket_reservation"
-
Create tables and run server
go run main.go migrate-db go run -tags debug main.go serve-api
-
Connect to psql
docker exec -ti ticket_reservation_postgres psql -U postgres
Uses autocannon with config:
connections: 80
duration: 10
4 POST requests. Each request reserves 1 ticket from 1 event
excludeErrorStats: true
Start by sending a GET request to populate DB (ONCE) with
- EventID 1 Quota 10000
- EventID 2 Quota 10000
- EventID 3 Quota 10000
- EventID 4 Quota 10000
curl localhost:9092/api/v1/pop
Then run load_test/cannon.js
with updated customer tokens
P.S. Need tokens because my implementation uses jwtclaims to get user data 🤣
Phase | Requests Sent | Avg Latency | Avg Throughput |
---|---|---|---|
1 Memory only | 9307 | 85.97 | 300800 |
2 Postgres only (with retry) | 713 | 513.71 | 10302.21 |
3 Postgres with batch jobs in memory | 4992 | 161.47 | 119737.6 |
4 Postgres + Redis | 2958 | 265.96 | 62724 |
docker build -t ticket_reservation_server .
docker run --rm -ti -p 9092:9092 ticket_reservation_server serve-api
docker run --rm -ti --entrypoint="/bin/bash" ticket_reservation_server