🚀 High-concurrency ticket booking backend designed for war tiket scenarios: no overselling, fair reservation, and operational visibility out of the box.
Most ticket-war systems fail in one or more of these areas:
⚠️ race condition leads to overselling⚠️ synchronous write path melts under spike⚠️ poor incident visibility in real-time⚠️ unfair reserve/confirm flow for users
This MVP addresses those directly:
- ✅ Atomic reserve in Redis for real-time stock consistency
- ✅ Kafka decoupling for async persistence and better API responsiveness
- ✅ TTL reservation + rollback for fairness and stock recovery
- ✅ Observability-first with Prometheus and Grafana
- ✅ Load-testable using k6 with practical SLO threshold
- 🛠️ Admin event and ticket category management
- ⚡ Realtime availability endpoint (backed by Redis stock)
- 🧱 Reserve endpoint with queue/backpressure control
- 💳 Confirm endpoint with idempotency and payment simulation
- ♻️ Expiry reaper for automatic stock release
- 🔐 JWT role auth (
admin/user) and IP throttling - 📘 Source-generated Swagger/OpenAPI
- 🐳 End-to-end Docker stack (API, Worker, Redis, Kafka, Postgres, Prometheus, Grafana)
Client
-> API (Go)
-> Redis (atomic stock + reservation TTL)
-> Kafka (reserved/confirmed/expired events)
-> Worker (Go consumer)
-> PostgreSQL
Metrics: API + Worker -> Prometheus -> Grafana
# 1) 🚀 boot stack
docker compose up -d --build
# 2) 🔑 generate tokens
go run ./cmd/token --role=admin --sub=admin-1 --secret=dev-secret
go run ./cmd/token --role=user --sub=user-1 --secret=dev-secret
# 3) 📊 open docs and dashboards
# Swagger: http://localhost:8080/swagger/index.html
# Prometheus: http://localhost:9090
# Grafana: http://localhost:3000 (admin/admin)Core endpoints:
POST /events(admin)POST /events/{id}/ticket-category(admin)GET /events/{id}/availabilityPOST /reserve(user)POST /confirm(user)GET /healthGET /metricsGET /swagger/index.html
Detailed API examples and schemas:
k6 scenario included in repository:
- file:
k6/reserve.js - target threshold:
p(95) < 200ms
Run benchmark:
USER_TOKEN=<USER_TOKEN> \
EVENT_ID=<EVENT_ID> \
BASE_URL=http://localhost:8080 \
RATE=150 DURATION=20s PRE_VUS=150 MAX_VUS=1000 \
k6 run k6/reserve.jsTest and validation playbook:
- Project overview:
docs/overview.md - Architecture:
docs/architecture.md - API guide:
docs/api.md - Operations runbook:
docs/operations.md - Testing guide:
docs/testing.md - Swagger artifacts:
docs/swagger
go test ./...CI runs test on push/PR via:
.github/workflows/ci.yml
MIT License. See LICENSE.