VAISHAK S
VAISHAK S. — BACKEND & SYSTEMS ARCHITECT
Back to Projects
Systems Architecture

Flash Sale Concurrency Engine

High-Throughput distributed purchase coordinator

View Source Code
Project Details
Role
Lead Backend Developer
Timeline
3 Months (R&D)
Technologies
JavaSpring BootPostgreSQLRedisDocker Compose
Project Impact
Throughput
5k+ req/sec
Cache Latency
< 15ms
Oversell Rate
0.00%

1. Context

In high-volume e-commerce flash sales, simultaneous transaction requests overload traditional databases. This leads to double-spending, inventory overselling, and thread pool exhaustion, creating revenue loss and system instability.

2. Constraints

The engine had to maintain strict ACID consistency while processing traffic spikes of over 5,000 requests per second. It was limited to standard database resource sizes without scaling costs, utilizing only Docker-based containerized stacks.

3. Approach

I evaluated standard database row-level locking (SELECT FOR UPDATE) but discarded it due to extreme database lock contention and connection bottlenecks. Instead, I designed a pre-decoding token bucket flow utilizing Redis-based distributed atomicity. High-velocity requests hit memory first, reserving inventory instantly, and only successful decrements trigger asynchronous database writes.

4. Craft

Implemented atomic inventory decrements using Lua scripts inside Redis to guarantee thread-safety. Integrated PostgreSQL persistence via Hibernate with a global transaction manager to resolve rollback integrity. Containerized the entire infrastructure (Java API, PostgreSQL database cluster, Redis sentinel) using Docker Compose for reproducible deployment and local profiling.

5. Outcome

Zero inventory oversell events under simulated load tests of 100 concurrent threads. Redis transaction times stabilized at <15ms, reducing database write burden by 85%. Developed an recovery flow that restores inventory tokens back to the cache if a database writing transaction fails.