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
Software Engineering Fundamentals
Software Engineer
Flipkart
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

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
race conditions
mutual exclusion
reservation with TTL
idempotency
lock granularity
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample Answer
Requirements
  • reserve(sku, qty) returns a hold id or None when stock is insufficient; never oversell.
  • confirm(hold_id) turns a live hold into a sale; returns False if 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 ...


Submit Your Answer
Markdown supported