Design an inventory management system
medium 80 minCount goods in several places, promise them to orders without ever promising too much, ship or let go, and explain every count.
Watch lesson4:28
Requirements
What it does, and what it does not
The point: each requirement should name a method or a rule. If it names neither, it belongs to another system.
Functional
What it must do
| Requirement | Becomes |
|---|---|
| Goods arrive at a place, with a reason | receive(sku, place, qty, ref) |
| Show how many may still be sold | available(sku) |
| Promise several products, all or none | reserve(order, wanted, seconds) |
| Send a promised order once | ship(id) |
| Cancel a promise | release(id) |
| A promise ends by itself | expires_at and expire_due() |
| Choose the place by a rule that can change | PickPolicy |
| Say once when a line becomes low | LowStock |
| Explain every count | Movement, append only |
Rules
What must always be true
- 1
0 ≤ held ≤ on hand
For every line, after every call, also after one that failed.
- 2
The sum of movements is on hand
For every line. The ledger is the proof.
- 3
Held is the sum of open promises
For every line, the picks of all
HELDreservations add up toheld. - 4
One ending
A promise leaves HELD once.
These four sentences are worth more than a diagram. They decide what a method must check, and later they become the tests.
Not functional
Speed, threads, numbers
Threads
Many at once. No order may see half of another.
Size
Assume 10,000 products in 5 places: 50,000 lines. They fit in memory easily.
Rate
Assume 50 orders a second at peak. At 20 microseconds under the lock it is busy for 1 ms in each second.
Ask
Questions, and what each answer decides
| They say | You write |
|---|---|
| "One place only" | No policy. The key is the product |
| "Take what is there" | reserve returns what was held and what is missing |
| "Jam has a date" | Batches inside the line |
| "Each item has a serial number" | A set of pieces, as in the parking lot |
| "We may promise what arrives on Monday" | Incoming as a third count, with a date |
| "It must survive a restart" | The ledger and open promises are stored; counts are rebuilt |
In scope
- Counts by product and place
- Reservations with an end
- Place choice
- Alerts and ledger
Out of scope, said aloud
- Prices and payment
- Suppliers and buying
- Packing and labels
- User accounts
- Several machines