Katkat

Design a Product Inventory and Pricing Service

Moody'sSoftware Engineer · Onsite

Last updated

Design a high-throughput product catalog, dynamic pricing, and inventory management service that delivers low-latency browsing while guaranteeing transactional correctness and preventing overselling at checkout.

Scenario

Design an e-commerce Product, Pricing, and Inventory Service. Customers frequently browse product pages, search catalogs, and review availability badges, while an order processing service coordinates inventory deductions and price verification during checkout. Back-office merchandising teams and algorithmic pricing engines regularly update base prices and promotional discounts.

Functional Requirements

  • Get Product Details: Retrieve product metadata, authoritative active price, and real-time inventory availability status.
  • Update Pricing: Support authorized price updates from merchandising tools or automated pricing engines with auditability.
  • Reserve & Decrement Inventory: Atomically check and reserve stock during checkout to prevent overselling, and roll back if payment fails.

Non-Functional Requirements & Scale

  • Scale:
    • Catalog size: 20 million active SKUs.
    • Read throughput: 100,000 queries per second (QPS) peak.
    • Write/Reservation throughput: 2,000 operations per second peak, with potential spikes of up to 10,000 QPS on single "flash-sale" SKUs.
  • Performance: p99 read latency < 25 ms for browsing views.
  • Consistency vs. Availability:
    • Product browsing can tolerate slight eventual consistency (e.g., stale stock counts within seconds).
    • Checkout validation requires strict consistency for price verification and zero overselling for inventory.
  • Security & Authorization: Write APIs (pricing, stock adjustments) must be strictly authenticated and role-authorized.

Key Areas to Cover

  1. API Design: Define the core endpoints for browsing, price updates, and stock reservations, including idempotency mechanisms.
  2. Data Storage & Modeling: Compare SQL vs. NoSQL storage paradigms. Determine how to partition product metadata, current pricing, and inventory ledger records.
  3. Caching & Concurrency: Detail your caching tiers (e.g., Redis, CDN) and invalidation strategies. Explain your approach to handling concurrency on hot items (e.g., optimistic locking, conditional database updates, or in-memory reservation queues).
  4. Failure Recovery & Checkout Flow: Explain how the service interacts with the checkout pipeline to guarantee that stale browser prices cannot be exploited and that abandoned checkouts cleanly release reserved stock.

Hints

Hint 1

Consider decoupling static product catalog attributes from highly volatile, transactional data like stock balances and active promotions.

Hint 2

Conditional database updates (such as `UPDATE inventory SET available = available - qty WHERE sku = :sku AND available >= qty`) can avoid distributed locking overhead while preventing negative stock.

Hint 3

Use cryptographic price quotes or versioned price IDs generated at cart confirmation to ensure the price paid matches the price displayed.

Follow-up questions

  • How would you handle a flash-sale scenario where 50,000 concurrent requests compete for 100 units of a single hot SKU?
  • How would you implement an automated, reliable stock expiration mechanism for carts abandoned after reservation?
  • How does your architecture adapt if inventory is distributed across multiple regional fulfillment centers?