Skip to content

Repository files navigation

Concert Booking API

Go Architecture Docker Kafka Redis PostgreSQL Observability Load Test Swagger Status

🚀 High-concurrency ticket booking backend designed for war tiket scenarios: no overselling, fair reservation, and operational visibility out of the box.

✨ Why This Project

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

🎯 What You Get

  • 🛠️ 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)

🧭 System Snapshot

Client
  -> API (Go)
     -> Redis (atomic stock + reservation TTL)
     -> Kafka (reserved/confirmed/expired events)
        -> Worker (Go consumer)
           -> PostgreSQL

Metrics: API + Worker -> Prometheus -> Grafana

⚡ Quick Start (2 Minutes)

# 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)

📡 API Surface

Core endpoints:

  • POST /events (admin)
  • POST /events/{id}/ticket-category (admin)
  • GET /events/{id}/availability
  • POST /reserve (user)
  • POST /confirm (user)
  • GET /health
  • GET /metrics
  • GET /swagger/index.html

Detailed API examples and schemas:

🧪 Performance & Validation

k6 scenario included in repository:

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.js

Test and validation playbook:

📚 Documentation Map

👨‍💻 Developer Workflow

go test ./...

CI runs test on push/PR via:

  • .github/workflows/ci.yml

📄 License

MIT License. See LICENSE.

About

High-concurrency ticket booking backend designed for war tiket scenarios: no overselling, fair reservation, and operational visibility out of the box.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages