Oversell-Proof Inventory Holds for a Big Billion Days Flash Sale
Last updated: November 29, 2026
Quick Overview
Implement a thread-safe inventory service where checkout reserves units with an expiring hold, payment confirms the hold, and expired or cancelled holds return stock, so that a flash sale with thousands of concurrent buyers never sells more units than exist.
Flipkart
November 29, 20260
0
0 solved
Implement a thread-safe inventory service where checkout reserves units with an expiring hold, payment confirms the hold, and expired or cancelled holds return stock, so that a flash sale with thousands of concurrent buyers never sells more units than exist.
Flipkart's SDE-2 and SDE-3 machine-coding and low-level design rounds often center on Big Billion Days style contention: a 10,000 unit phone launch where lakhs of users hit Buy Now in the same second. The interviewer is checking whether you can find the race in check-then-decrement, pick a locking scope that is correct, and handle abandoned checkouts without leaking stock.
What the Interviewer Expects
- Identify the check-then-act race and make reserve atomic
- Model holds with expiry so abandoned payments return stock
- Make confirm and cancel idempotent and safe after expiry
- Inject a clock so expiry is testable
- Discuss lock striping or per-SKU locks and how this maps to a database or Redis
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you move this to Redis or MySQL so multiple app servers share stock?
- A single global lock becomes the bottleneck at 50k reservations per second. What do you change?
- Payment confirms one second after the hold expired. What should happen and who decides?
- How do you reconcile if the service crashes with holds in memory?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
reserve(sku, qty)returns a hold id orNonewhen stock is insufficient; never oversell.confirm(hold_id)turns a live hold into a sale; returnsFalseif the hold expired.- `cancel(hold_id...
High-Level Design
The naive if stock >= qty: stock -= qty is two steps; two threads can both pass the check with one unit left. All mutations of available and holds must happen under one critical section. Expiry ...