A production-ready Flash Sale Engine built with Spring Boot, designed to safely handle massive concurrent traffic and limited-stock purchases.
This project simulates real-world flash sale systems used by Amazon, Flipkart, Myntra, where thousands of users attempt to buy the same product at the same time—without overselling, crashing, or being abused by bots.
- 🛡️ User-based Rate Limiting (anti-bot & abuse protection)
- 🛒 Atomic Purchase Flow (no overselling)
- ⚙️ High-Concurrency Safe Design
- 🚀 Redis-powered performance optimization
- 📦 Kafka-based asynchronous order processing
- 🔐 JWT-secured APIs with Spring Security
- 🧪 RESTful API architecture
- 🐳 Docker-ready deployment
- 📊 Clean & scalable layered architecture
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot |
| Security | Spring Security + JWT |
| Database | MySQL |
| Cache | Redis |
| Messaging | Apache Kafka |
| ORM | JPA / Hibernate |
| Build Tool | Maven |
| Containerization | Docker |
| Logging | Logback |
- Applied per user to restrict excessive purchase attempts
- Protects against DDoS, brute-force, and bot traffic
- Implemented using Redis counters for low-latency checks
- Exceeds limit → returns
429 TOO_MANY_REQUESTS
- Guarantees atomic stock decrement
- Prevents race conditions and overselling
- Uses transactional boundaries at service/database level
- Designed to stay consistent under thousands of parallel requests
-
Decouples API layer from order processing
-
Improves throughput, scalability, and fault tolerance
-
Enables future extensions like:
- Retry queues
- Dead Letter Queue (DLQ)
- Event-driven analytics
FlashSaleEngine
├── controller # REST Controllers
├── service # Business Logic
├── repository # Database Access Layer
├── model # Entities & DTOs
├── security # JWT & Security Config
├── config # Application Configurations
├── kafka # Kafka Producer & Consumer
├── redis # Cache & Rate Limiting Logic
└── exception # Global Exception Handling
POST /buy/{productId}| Status | Description |
|---|---|
200 OK |
Purchase successful |
429 TOO_MANY_REQUESTS |
Rate limit exceeded |
400 BAD_REQUEST |
Out of stock / invalid request |
if (!rateLimitingService.tryAccess(user.getId())) {
return ResponseEntity
.status(HttpStatus.TOO_MANY_REQUESTS)
.body("Too many attempts, try again later!");
}docker build -t flash-sale-engine .
docker run -p 8080:8080 flash-sale-engine- Java 21
- Maven
- MySQL
- Redis
- Apache Kafka
git clone https://github.com/Ash8389/FlashSaleEngine.git
cd FlashSaleEngine
mvn clean install
mvn spring-boot:runSimulate real flash sale traffic using JMeter.
- Validate rate limiting
- Ensure zero overselling
- Measure response time under load
- Verify system stability
- Threads: 1000+
- Ramp-up: 10–30 seconds
- Loop Count: 1
Request
-
POST /buy/{productId} -
Headers:
Authorization: Bearer <JWT_TOKEN>Content-Type: application/json
jmeter -n -t flash-sale-test.jmx -l results.jtl- ✔️ Successful purchases (
200 OK) - ⛔ Excess traffic blocked (
429 TOO_MANY_REQUESTS) - 🔒 No negative stock values
- ⚡ Stable response times
- Distributed locking with Redisson
- Monitoring with Prometheus & Grafana
- Retry mechanism + DLQ
- Kubernetes deployment
- Advanced stress & chaos testing
Ashish Kumar Jha Backend Developer | Java | Spring Boot | Redis | Kafka
🔗 GitHub: https://github.com/Ash8389
⭐ If you find this project useful, consider starring the repository!