5. You are designing an inventory system that must handle multiple warehouses. Which design approach best ensures accurate stock counts across warehouses and prevents overselling?
hard
A. Maintain separate stock counts per warehouse and use transactions to update atomically
B. Keep a single global stock count without warehouse details
C. Update stock counts asynchronously without locking
D. Allow negative stock counts to handle overselling
Solution
Step 1: Consider multi-warehouse stock tracking
Each warehouse should have its own stock count to track inventory accurately.
Step 2: Ensure atomic updates to prevent overselling
Using transactions or locks ensures stock updates are consistent and prevent race conditions.
Final Answer:
Maintain separate stock counts per warehouse and use transactions to update atomically -> Option A
Quick Check:
Atomic updates + per-warehouse stock = accurate inventory [OK]
Hint: Use atomic transactions and per-warehouse counts [OK]