System Design: Multi-Warehouse, Multi-Channel Inventory Service
You are designing an inventory service for an e-commerce platform that sells across multiple sales channels (e.g., web, marketplace, retail partners) and fulfills from multiple warehouses. The service must prevent overselling under concurrent load and support cart reservations and order commits.
Requirements
-
Scope and Responsibilities
-
Track inventory at the granularity of SKU × warehouse.
-
Support per-channel inventory policies (e.g., safety stock, backorder rules).
-
Maintain real-time availability for browsing and checkout.
-
Core Operations and APIs
-
Adjust: apply deltas from physical counts, transfers, damages, or WMS/ERP updates.
-
Reserve: hold stock for a cart or pre-authorized order with TTL.
-
Commit: finalize reservation on payment/ship confirmation.
-
Release: free a reservation on cancel, expiration, or failure.
-
Define request/response shapes, idempotency, and retry behaviors.
-
Data Model
-
Entities for SKU, Warehouse, Inventory (with on_hand, reserved, inbound, safety_stock, damaged), and Reservation.
-
Support fields for channel-specific constraints and policies.
-
Consistency and Concurrency
-
Define invariants and the consistency model needed to prevent oversell under concurrent updates.
-
Describe how you handle multi-warehouse reservations and cross-row transactions.
-
Idempotency and Retries
-
Strategy to make all mutation APIs idempotent and safe under at-least-once delivery.
-
Eventing
-
Publish stock change events for downstream systems (e.g., search, merchandising, marketplaces).
-
Ensure ordering and delivery guarantees; describe the outbox/CDC approach.
-
Reconciliation with ERP/WMS
-
How the service integrates with external systems, which system is the source of truth for physical stock, and how periodic reconciliation works.
-
Scaling and Partitioning
-
Partitioning strategy, hot-key mitigation, read/write scaling, and latency targets.
-
Caching and materialized views for browse availability.
-
Business Scenarios and Failure Handling
-
Backorders and pre-sell against inbound.
-
Returns and restocking flows.
-
Degraded modes during outages (DB, message bus, ERP/WMS).
Deliver:
-
A clear data model.
-
API designs for adjust, reserve, commit, and release with idempotency.
-
Consistency model and concurrency control strategy.
-
Eventing model and reconciliation plan.
-
Scaling/partitioning approach.
-
Handling of backorders, returns, and outages.