Design an inventory system that tracks stock and supports availability queries and stock-changing operations. Explain how concurrent requests avoid overselling and how reservations, successful orders, and cancellations affect available inventory.
### Constraints & Assumptions
The source names inventory-system design without a specific domain or workload. Reservations are an explicit design choice to discuss, not a claimed original API. Clarify whether stock is tracked globally or by location.
### Clarifying Questions to Ask
- Are stock units interchangeable by SKU, individually serialized, or both?
- Do orders reserve stock before payment, and when do reservations expire?
- Must availability be exact or may display reads be slightly stale?
```hint Separate on-hand from available
A unit may still physically exist while already being committed to another order.
```
### What a Strong Answer Covers
- A stock model distinguishing on-hand, reserved, and committed quantities.
- Atomic conditional reservations and idempotent state transitions.
- Expiration/cancellation races and reconciliation with physical adjustments.
### Follow-up Questions
- How would a multi-item order avoid partially reserving only some items?
- What changes for stock distributed across warehouses?
Overview: Design inventory tracking with atomic reservations, oversell prevention, idempotent order transitions, expiry-race handling, and auditable stock movements.
Design an inventory system that tracks stock and supports availability queries and stock-changing operations. Explain how concurrent requests avoid overselling and how reservations, successful orders, and cancellations affect available inventory.
Constraints & Assumptions
The source names inventory-system design without a specific domain or workload. Reservations are an explicit design choice to discuss, not a claimed original API. Clarify whether stock is tracked globally or by location.
Clarifying Questions to Ask Guidance
Are stock units interchangeable by SKU, individually serialized, or both?
Do orders reserve stock before payment, and when do reservations expire?
Must availability be exact or may display reads be slightly stale?
What a Strong Answer Covers Guidance
A stock model distinguishing on-hand, reserved, and committed quantities.
Atomic conditional reservations and idempotent state transitions.
Expiration/cancellation races and reconciliation with physical adjustments.
Follow-up Questions Guidance
How would a multi-item order avoid partially reserving only some items?
What changes for stock distributed across warehouses?