KatInterview

Design a Flash-Sale Resilient Inventory Engine

System DesignModel answer
HardModel answerSystem Designsystem-designconcurrencydistributed-systems

Last updated

Design a multi-warehouse e-commerce inventory system handling flash sales without overselling, focusing on high availability, concurrency control, and idempotency.

Design an enterprise-grade inventory engine for an e-commerce platform operating across multiple regional fulfillment centers.

Core Functional Requirements

  1. Stock Lifecycle: Support Reserve (hold stock temporarily for checkout), Release (cancel hold or handle expiration), and Purchase (permanently decrement stock upon successful payment).
  2. Catalog & Warehouse Breakdown: Allow clients to query aggregate stock availability for a SKU as well as stock breakdown per fulfillment center.
  3. Idempotency & Reliability: Guarantee at-least-once downstream event publishing (order created, inventory reserved) and ensure all state-mutating APIs support idempotent retries.

Key Technical Challenges & Constraints

  • Absolute Invariant: Zero overselling. Under no circumstances may aggregate reservations exceed available physical stock.
  • High Throughput & Spikes: System must handle flash sales driving 50,000 read requests per second and 5,000 write operations per second, often concentrated on a tiny fraction of hot SKUs.
  • High Availability: Target 99.99% operational uptime across regional network degrades and partial service outages.

Expectations

Walk through the architectural design, detailing:

  • System components, API interfaces, and relational schema.
  • Concurrency strategies to avoid race conditions under extreme contention.
  • Scaling paradigms (CQRS, read caching, sharding strategies, and hot-key counter techniques).
  • Reliability patterns (saga orchestration, outbox pattern, rate-limiting, and disaster recovery).

Hints

Hint 1

Reads can tolerate slight event-driven staleness, but reserve writes require strict linearizability at the database row level. Avoid read-modify-write patterns in application code.

Hint 2

For hot SKUs receiving thousands of updates per second on a single row, consider counter-splitting or pre-filtering traffic with atomic Redis operations.

Hint 3

To safely bridge the database write and Kafka message delivery without two-phase commit overhead, implement the Transactional Outbox pattern with CDC.