solidcodersolidcoder
Explore Courses
solidcodersolidcoder

Practical courses for software engineering interviews — no gatekeeping, no fluff.

Company-wise Questions

  • Flipkart Machine Coding Questions
  • Swiggy Machine Coding Questions
  • Meesho Machine Coding Questions

Machine Coding Tutorial

  • Machine Coding Tutorial

Explore

  • Courses
  • About
  • Privacy Policy
  • Terms

© 2026 solidcoder · Practical courses for software engineering interviews.

Built for the AI era — learn by doing.

Home/Machine Coding/Meesho Machine Coding Questions/Inventory Management Service
Chapters — Meesho Machine Coding Questions▾

Inventory Management Service

Machine Coding·SDE-2+·5 min read·Sep 11, 2026

Design Meesho's in-memory inventory service — stock blocking with a 5-minute hold, auto-release, and safe concurrent checkout at scale.

Asked inMeesho

Design an in-memory inventory service for an e-commerce platform. The core twist: stock isn't deducted the moment a user clicks "buy" — it's blocked for a short window while payment is in progress, then either confirmed (permanently deducted) or automatically released if the user never completes checkout.

What the round tests

This one tests whether you can design a time-bounded reservation system correctly — blocking stock without overselling it, releasing it automatically on timeout, and keeping every operation safe when a huge number of users are checking out concurrently.

Scale context

Scale to consider: 10M active users, 5M products, ~1M orders/day — in-memory only, so thread-safety and explicit race handling are P0, not optional.

Objective

The primary objective is to design and implement a thread-safe, in-memory inventory service for 10M users / 5M products / ~1M orders/day that supports adding and restocking products, blocking stock for a 5-minute checkout window, and either confirming or auto-releasing that blocked stock — with explicit handling of race conditions.

Functional Requirements

Two tiers of scope

Requirements are split into two tiers so you know what to prioritize under time pressure: build first, and build if time allows.

Part 1 — Core Requirements

Core functionality you must build and get working first.

Core APIs
API
Behavior
addProduct(productId, name, count)
Registers a new product with an initial stock count.
getInventory(productId)
Returns the currently available (unblocked) stock for a product.
updateInventory(productId, count)
Supplier restocks a product, increasing available stock.
blockInventory(productId, count, orderId)
Reserves stock against an order when the user initiates payment. The block holds for 5 minutes and reduces available stock without yet deducting it permanently.
confirmOrder(orderId)
Permanently deducts the previously blocked stock once payment succeeds. If confirmOrder isn't called within 5 minutes of blocking, the block is released automatically and the stock returns to available.
Constraints

In-memory only — no DB. Thread-safe for 10M active users, 5M products, ~1M orders/day; blocking, confirming, and auto-releasing can race on the same product at the same instant — handle race conditions explicitly.

Part 2 — Suggested Extensions

Suggested additional APIs
API
Why it's worth adding
cancelOrder(orderId)
Lets a user or the payment gateway explicitly release a block early (e.g. payment failed immediately) instead of waiting the full 5 minutes.
getOrderStatus(orderId)
Exposes whether an order's block is PENDING, CONFIRMED, RELEASED, or EXPIRED — useful for debugging and for the checkout UI to poll.
getLowStockProducts(threshold)
Returns products whose available count has dropped below a threshold, for supplier restock alerts.
blockInventoryBulk(items, orderId)
Blocks stock for multiple products in a single order atomically — either every line item gets blocked, or none do, avoiding a half-blocked cart.
Idempotency & duplicate confirm

confirmOrder(orderId) and cancelOrder(orderId) should both be idempotent — calling either twice (e.g. due to a retried payment webhook) must not double-deduct stock or double-release it.

Example Usage: Full Walkthrough

Here's how a sample session might run end-to-end, one step at a time.

1. Register and restock a product

> addProduct("p1", "Wireless Mouse", 100)
✅ Product p1 added with stock 100.

> updateInventory("p1", 20)
✅ Stock updated. Available: 120.

2. Block stock during checkout

> blockInventory("p1", 5, "order101")
✅ 5 units blocked for order101. Available: 115. Block expires in 5 min.

> getInventory("p1")
115

3. Confirm the order before the block expires

> confirmOrder("order101")
✅ Order order101 confirmed. 5 units permanently deducted. Available: 115 (unchanged — already excluded).
Total stock: 115.

4. A block that's never confirmed auto-releases

> blockInventory("p1", 10, "order102")
✅ 10 units blocked for order102. Available: 105. Block expires in 5 min.

... 5 minutes pass with no confirmOrder call ...

⏱ Block for order102 expired. 10 units released. Available: 115.

5. Concurrent blocks can't oversell

> blockInventory("p1", 100, "order103")   // from thread A
> blockInventory("p1", 50,  "order104")   // from thread B, same instant

✅ order103: 100 units blocked. Available: 15.
❌ order104: only 15 units available, cannot block 50.
Result

Confirmed stock is deducted permanently, an unconfirmed block silently expires and returns its units to availability, and two concurrent block attempts on the same product never oversell — the second is correctly rejected once the first exhausts the remaining stock.

What Interviewers Look For

Evaluation criteria
Criterion
What's assessed
Correct concurrency
Blocking, confirming, and auto-expiry never race — safe at 1M orders/day concurrency.
Clean expiry mechanism
The 5-minute auto-release is implemented deliberately (e.g. a scheduler or lazy expiry check), not bolted on as an afterthought.
Entity modelling
Products, stock counts, and blocks are modelled as distinct, well-defined entities rather than loose maps of numbers.
Extensibility
Adding suggested extensions like cancelOrder or bulk blocking shouldn't require touching the core blocking logic.
Demoable code
A driver/main program exercises blocking, confirming, expiry, and the oversell-prevention case.
Up next1/2
Part 1 · SDE-2+
←
← Prev Chapter
Splitwise
5 min
Next Chapter →
Car Pooling
5 min · continue reading
→

Enroll in machine coding mastery series

₹30,000₹3,00090% OFF
Enroll Now →

Use code SOLID50 · 3 years · 40+ lessons

On this page
  • Objective
  • Functional Requirements
    • Part 1 — Core Requirements
    • Part 2 — Suggested Extensions
  • Example Usage: Full Walkthrough
  • What Interviewers Look For