A production-grade Flash Sale system built on a Microservices architecture to solve real-world Race Condition problems at scale β featuring a live Cyber HUD Admin Dashboard.
In a standard Flash Sale, thousands of users click "Buy" simultaneously. A naive implementation leads to:
- β Overselling β Stock goes negative because multiple threads read the same stock value at the same time.
- β Data Inconsistency β Orders are created for items that no longer exist.
- β System Collapse β A single monolithic server crumbles under the load.
This project solves all three using a distributed microservices architecture.
| Problem | Solution Used |
|---|---|
| Race Condition on stock | Redis DECRBY Atomic Operation (thread-safe, no lock needed) |
| Request overload | RabbitMQ Message Queue (order requests are queued, not processed simultaneously) |
| Single point of failure | Microservices (each service runs independently) |
| Slow inventory queries | Redis Cache (sub-millisecond reads) |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT (Browser) β
β React Dashboard β Flash Sale Page β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β HTTP / REST
βΌ
βββββββββββββββββββββββββββββββββββ
β API GATEWAY (Go) β
β Rate Limiting Β· Routing β
βββββββ¬ββββββββββββ¬ββββββββββββββββ
β β
βΌ βΌ
ββββββββββββ ββββββββββββββββ βββββββββββββββββββββββββββ
β Product β β Inventory βββββΆβ Redis (Atomic Counter) β
β Service β β Service β β DECRBY for Stock β
β (Go) β β (Go) β βββββββββββββββββββββββββββ
ββββββββββββ ββββββββ¬ββββββββ
β Publish
βΌ
βββββββββββββββββββ βββββββββββββββββββββββββ
β RabbitMQ ββββΆβ Order Service (Go) β
β Message Queue β β Consumes & Persists β
βββββββββββββββββββ βββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββ
β PostgreSQL DB β
β (Persistent) β
ββββββββββββββββββββ
Cyber HUD Theme with full Dark / Light Mode toggle β real-time system monitoring at a glance.
| Feature | Description |
|---|---|
| π Live Stats | Stock, Orders, Queue length update every 4 seconds |
| π’ Service Health | Status indicator for Gateway, Order Processor, Inventory Sync |
| π₯οΈ Security Logs | Live feed of system events with timestamps |
| π¨ Dark / Light Mode | Smooth theme transition via CSS Variables |
| β‘ Control Center | Trigger sessions, pause sales, flush cache |
| Layer | Technology | Purpose |
|---|---|---|
| Language | Go (Golang) | High-performance, concurrent microservices |
| Web Framework | Fiber | Express-like HTTP framework for Go |
| Message Broker | RabbitMQ | Async order queuing |
| Cache & Atomic Ops | Redis | Sub-ms stock reads, Race Condition prevention |
| Database | PostgreSQL | Persistent order & product storage |
| Containerization | Docker + Compose | One-command environment setup |
| Layer | Technology | Purpose |
|---|---|---|
| Framework | React 18 + Vite 5 | Fast SPA with HMR |
| Styling | Vanilla CSS | Custom Cyber HUD design system |
| Icons | Lucide React | Consistent icon library |
| Fonts | Orbitron + Rajdhani | Futuristic HUD typography |
git clone https://github.com/yourusername/nexcore-flashsale-engine.git
cd nexcore-flashsale-enginedocker-compose up -dcd frontend
npm install
npm run devDashboard will be available at
http://localhost:5173
# In separate terminals:
cd backend/gateway && go run main.go
cd backend/product && go run main.go
cd backend/inventory && go run main.go
cd backend/order && go run main.gonexcore-flashsale-engine/
βββ backend/
β βββ gateway/ # API Gateway - routing & rate limiting
β βββ product/ # Product & Flash Sale schedule management
β βββ inventory/ # Stock management with Redis atomic ops
β βββ order/ # Order processing via RabbitMQ consumer
β βββ shared/ # Shared models, config, utilities
βββ frontend/
β βββ src/
β β βββ App.jsx # Main Dashboard component
β β βββ index.css # Cyber HUD Design System
β βββ package.json
βββ docker-compose.yml
βββ README.md
// β Unsafe (classic race condition)
stock := getStockFromDB()
if stock > 0 {
updateStock(stock - 1) // Another goroutine may do the same!
}
// β
Safe (atomic Redis operation)
remaining, err := rdb.Decr(ctx, "product:stock:1").Result()
if remaining < 0 {
rdb.Incr(ctx, "product:stock:1") // Rollback
return errors.New("out of stock")
}// Producer (Inventory Service) β publishes order to queue
ch.Publish("", "order_queue", false, false, amqp.Publishing{
ContentType: "application/json",
Body: orderJSON,
})
// Consumer (Order Service) β processes orders from queue
msgs, _ := ch.Consume("order_queue", "", true, false, false, false, nil)
for msg := range msgs {
processAndSaveOrder(msg.Body) // Saved to PostgreSQL
}This project is licensed under the MIT License β see the LICENSE file for details.
Built with β and a lot of debugging sessions
β Star this repo if you find it useful!