AlgoViz

Design an inventory management system

medium 80 min

Count goods in several places, promise them to orders without ever promising too much, ship or let go, and explain every count.

Watch lesson4:28

Grow the design

Start with the smallest system that works. Change it only when something breaks.

Grow it

Five steps, each forced by a sentence

  1. 1

    A map of numbers

    Forced by: how many do we have?

  2. 2

    Two counts in a line

    Forced by: people pay later.

  3. 3

    A reservation with picks

    Forced by: give back exactly what was held.

  4. 4

    A lock and two phases

    Forced by: several products, several threads.

  5. 5

    Policy, ledger, listener

    Forced by: several places, why, and running low.

The design to reach: one coordinator, one guarded line, plain records

Inventory- lines: Map<sku+place, StockLine>- reservations: Map<id, ...>- movements: List<Movement>- lock: Lock+ receive(sku, place, qty, ref)+ reserve(order, wanted, seconds)+ ship(id) / release(id)+ expireDue(): int

1/7Start from the verbs

Goods arrive, are promised, leave, or the promise ends. Four verbs on one coordinator, Inventory. Callers see nothing else.

implementsusesowns (dies together)

A question mark means that the answer may be nothing. Not enough stock is an everyday answer for a policy.