- Source: LeetCode – Inventory API
- Language: Python 3.11
- Difficulty: Hard
- Time Limit: 75 min
- AI Agent: Allowed
Stockroom is a private, MongoDB-backed inventory API. Successful creates disappear, updates return stale data, and users can access other accounts' items.
Persist items to the real database and return what was actually stored. Authenticate every request, validate its input, and scope all reads, updates, and deletes to the owner. Updates must check and increment the version atomically, so concurrent edits on one version succeed exactly once. Enforce unique SKUs per owner, and map storage errors to the correct status codes.
- MongoDB persistence and CRUD
- Authorization and ownership checks
- Optimistic locking and atomic updates
- Uniqueness constraints and concurrency
- Input validation and error mapping
- HTTP REST APIs and status codes
- Debugging
- Database
- Authorization
- Optimistic Locking
- Concurrency
- Input Validation
- REST API
- CRUD