coupon-redemption-system
A demo e-commerce system showing how Redis-based distributed locking prevents a limited coupon from being over-redeemed under heavy concurrent traffic.
This project is a learning demo that shows how to safely handle a coupon code with a limited number of uses when many people try to redeem it at the exact same moment. It walks through a classic problem in software systems called a race condition, and demonstrates the fix for it using a technique called distributed locking.
The example scenario is a flash sale coupon that can only be redeemed 100 times. If three copies of the same application are all running at once and none of them coordinate with each other, they can each read the count as 100, each subtract one, and each save 99 back, so far more than 100 people end up successfully redeeming a coupon meant for only 100. The project shows how adding a shared lock, backed by Redis, forces each running copy to take turns, so the count only ever decreases correctly no matter how many requests arrive together.
The system is built as several small services working together: a React web page for the user interface, a load balancer called Nginx that spreads incoming requests across three identical backend copies, those backend copies built with Spring Boot, a MySQL database that stores the coupons and their redemption history, and Redis acting purely as the shared lock. Everything can be started together using Docker, which packages each piece so it runs the same way on any machine.
The README documents the exact API endpoints for creating a coupon, listing coupons, redeeming one, and viewing redemption history, along with diagrams showing how a request flows through the load balancer, into a backend instance, through the lock, and into the database. This is meant as an educational reference for developers who want to see a working, realistic example of distributed locking rather than just reading about the concept, and no license is stated in the README.
Where it fits
- Study a real example of a race condition and how distributed locking fixes it.
- Learn how Nginx load balances requests across multiple backend instances.
- See a working microservices setup with Spring Boot, MySQL, and Redis together.
- Reference the API design for a coupon redemption and inventory system.