TicketPulse is an enterprise-grade, high-concurrency event ticketing backend engine designed to withstand extreme traffic spikes during flash sales. Engineered in Go (Fiber framework), the system guarantees zero overselling under concurrent demand through atomic inventory allocation using Redis Lua Scripts, real-time virtual queueing via Redis Sorted Sets (ZSET) & Server-Sent Events (SSE), and asynchronous, eventual-consistency order persistence leveraging Apache Kafka (KRaft mode) and PostgreSQL 16.
- Atomic Inventory Lock & Zero Overselling Guarantee: Solves race conditions at the memory layer by executing non-blocking, single-threaded Lua Scripts in Redis, preventing database deadlock and thread contention.
- Virtual Waiting Room Engine (Fair FIFO Queue): Enforces rate-limiting and access control using Redis ZSET, dynamically calculating rank and streaming live queue updates to clients over HTTP Server-Sent Events (SSE).
-
Asynchronous Event-Driven Order Processing: Offloads heavy relational database writes by publishing
OrderCreatedEventto an Apache Kafka event stream, consumed by decoupled background workers for idempotent persistence into PostgreSQL. -
Battle-Tested High Concurrency: Proven under stress testing to sustain 5,820+ RPS with sub-35ms
$P_{95}$ latency and 0.00% unexpected error rate.
sequenceDiagram
autonumber
actor Client as Client / Virtual Queue UI
participant Fiber as Go API Gateway (Fiber)
participant Redis as Redis 7 (Lua & ZSET)
participant Kafka as Apache Kafka Broker
participant Worker as Order Consumer Worker
participant DB as PostgreSQL 16 DB
%% Virtual Waiting Room Stream
Client->>Fiber: POST /api/v1/queue/join
Fiber->>Redis: ZADD event:queue timestamp UUID
Redis-->>Fiber: Rank position
Fiber-->>Client: Queue position confirmed
Client->>Fiber: GET /api/v1/queue/stream (SSE)
loop Every 2 Seconds
Fiber->>Redis: ZRANK event:queue UUID
Redis-->>Fiber: Current position
Fiber-->>Client: Stream event (queue_position)
end
%% Atomic Ticket Reservation
Client->>Fiber: POST /api/v1/tickets/reserve (Rank #1)
Fiber->>Redis: EVAL reserve_ticket.lua (Stock DECR)
alt Stock Available
Redis-->>Fiber: Status: RESERVED
Fiber->>Redis: ZREM event:queue UUID
Fiber->>Kafka: Publish OrderCreatedEvent (Async)
Fiber-->>Client: HTTP 202 Accepted (Order ID)
%% Asynchronous Event Consumer
Kafka->>Worker: Consume OrderCreatedEvent
Worker->>DB: INSERT INTO orders (Status: COMPLETED)
DB-->>Worker: Commit Transaction
else Stock Exhausted
Redis-->>Fiber: Status: SOLD_OUT
Fiber-->>Client: HTTP 409 Conflict (Sold Out)
end
Extensive load testing was executed using Grafana k6 simulating 500 Concurrent Virtual Users (VUs) executing high-concurrency booking flows over a 70-second execution window.
| Metric | Result | Threshold / Target | Status |
|---|---|---|---|
| Throughput (RPS) | 5,827.68 req/sec | > 1,000 req/sec | 🟢 PASS |
| Total Processed Requests | 408,208 Requests | N/A | 🟢 PASS |
| Average Response Latency | 12.72 ms | < 50 ms | 🟢 PASS |
| 95th Percentile Latency ( |
31.19 ms | < 200 ms | 🟢 PASS |
| 99th Percentile Latency ( |
61.84 ms | < 500 ms | 🟢 PASS |
| Unexpected System Error Rate | 0.00% | < 1.00% | 🟢 PASS |
| Successful Ticket Allocations | 10,000 / 10,000 Tickets | Zero Overselling | 🟢 PASS (100% Accurate) |
Business Logic Validation: Out of 204,104 reservation attempts under stock constraints (10,000 tickets available), exactly 10,000 transactions succeeded (
HTTP 200/202), while 194,104 requests were gracefully rejected withHTTP 409 Sold Out/ stock exhaustion, proving absolute race-condition protection.
- Language & Runtime: Go 1.22+ (Fiber v2)
- Primary Database: PostgreSQL 16 (pgxpool Connection Pool)
- In-Memory Cache & Lock: Redis 7.0 (Lua Execution & ZSET Data Structure)
- Event Streaming Platform: Apache Kafka (KRaft Single-Broker Controller Mode)
- Load Testing & QA: Grafana k6, FastHTTP Engine
- Containerization: Docker & Docker Compose
- Docker & Docker Compose installed
- Go 1.22+ (optional for local non-containerized execution)
- k6 CLI (for running performance tests)
git clone [https://github.com/iammjdev/ticketpulse-backend.git](https://github.com/iammjdev/ticketpulse-backend.git)
cd ticketpulse-backend
# Boot up PostgreSQL, Redis, and Kafka KRaft containers
docker-compose up -d
# Download Go dependencies
go mod download
# Start API Gateway Server (Runs on port :8080)
go run cmd/api/main.go
# Pre-warm ticket inventory (e.g., 10,000 items) and clear stale queue data
curl -X POST http://localhost:8080/api/v1/tickets/warmup \
-H "Content-Type: application/json" \
-d '{"event_id":"11111111-1111-1111-1111-111111111111","zone_id":"22222222-2222-2222-2222-222222222222","stock":10000}'
# Trigger k6 performance load script
k6 run scripts/k6_load_test.js
Distributed under the MIT License. See LICENSE for more information.