Design an Inventory Stock Control Domain
Model a physical-inventory domain that receives stock, reserves it safely, releases or fulfills reservations, and exposes current availability.
Design the low-level domain, database schema, and API contracts for a stock-control system.
For this exercise, assume the entire bounded practice contract that follows: stock means physical product inventory rather than financial securities; one inventory operator manages one warehouse; and the warehouse tracks catalog items by unique SKU.
Each item has nonnegative on-hand and reserved quantities, and available quantity equals on hand minus reserved. The operator can receive units, reserve available units against an external reference, release an active reservation, fulfill an active reservation, and read an item's balance and reservation status.
Each mutating request has a stable request ID: an exact retry returns the original outcome without applying inventory twice, while conflicting reuse is rejected. Reserving more than the available quantity fails without changing state.
Releasing or fulfilling an already terminal reservation is an idempotent no-op only when it is the exact retry of the original request; a different command is rejected. Concurrent commands for the same SKU must preserve nonnegative quantities and the invariant that reserved never exceeds on hand.
Assume the database is authoritative across process restarts. Sales, pricing, payments, supplier ordering, shipment routing, multi-warehouse transfers, and securities trading are out of scope. No implementation code is required.
After the core design, evaluate Singleton and static-keyword use cases without assuming that a process-local Singleton is globally unique.