ADR 0058: The warehouse flow model is deterministic code in its own module
Status: Accepted
Context
Floor Assessment scores which flow stage carries the most pressure, from the open monitor alerts alone (Floor Assessment). It cannot say what one stage does to the next, because the alerts carry no link between stages. Karyo's rows do carry those links: a received line has its putaway transport order, a fix assignment ties a forward bin to its SKU, a pick draws from a stock unit on a bin, a pick order serves a delivery order and its shipment.
The product owner set the warehouse flow model as step 2 of a planned sequence: a model of stages, capacity and queues with a built-in deterministic projection, rates learned from history, and a day-in-the-life simulator as its harness, rule-based only. It ships in two parts in Karyo 2.0.0. Part 1 is the model, the readers, the built-in projection and the learned rates. Part 2 is:
- the simulator harness: an arrival process, an advanceable clock and a seeded comparison of policy
R (the built-ins) against policy O (
TRAVEL_PATHdispatch with zone batching and nearest-neighbour routing); - the reorder replay migrated as one scenario of the shared model;
- the replay of a demo day (the UCI open-demand profile), reproduced within a stated tolerance;
- the read-only floor view on Locations;
- packing by consolidation group, where part 1 packed every delivery order on its own.
A judgment layer may choose among projected candidates, but this model computes the numbers, and it calls no model.
Decision
- A module of its own.
services/flow-serviceholdskaryo-flow-api(the model types,Outcomeand theProjectionSPI) andkaryo-flow-core(readers, the state builder and the built-inqueuesprojection). It is not insidekaryo-monitors-core: the model reads every stage, not the monitors' alerts, and the day simulator uses it as a library. - It reads Karyo's own rows and writes none. The readers are native SQL over the shared schema,
as reporting and the analytics engines read it (ADR 0011).
Forward bins come through the
FixAssignmentLookupSPI, the forecast throughSkuForecastLookup(declared inkaryo-forecasting-api, implemented byForecastService) and the dispatch order through the installation'sWorkDispatchStrategybean. A wave order's consolidation group comes throughConsolidationMembershipLookup(declared inkaryo-wave-api, implemented by the wave module over its own membership rule), so the address rule has one home. No foreign core is on its classpath. - Deterministic and rule-based. A projection is a pure function of a state, a candidate and a horizon: no I/O, no clock and no randomness. The built-in one is a discrete-event run whose ties break by a sequence number. The simulator's only randomness is its arrival process, drawn from a seed, so a seed always gives the same day and a comparison run is repeatable. Nothing in the module calls a model.
- One engine for the projection, the simulator and the reorder scenario. The simulator is the
projection's run with an arrival process and walking pickers, its clock advanced in steps. The
reorder backtest is the same run over one bin with lost-sales demand and an (s, Q) rule as the
candidate, behind the
ReorderPolicySimulatorSPI the Simulation page already reads, as its default (flow); the arithmetic replay stays selectable (lost-sales) and gives equal numbers. - The simulator lives in the module, not beside Karyo. Section 12 of the design report first proposed a separate simulator process; the settled sequence moved it into this module so the simulator and the product share one set of rules and read the same rows.
- A replay states its tolerance. A replayed day is reproduced when each compared measure (lines picked, picking person-hours, and orders shipped where a crew packs and ships) is within 10% of what Karyo's rows show.
- Learned where Karyo has the history, set where it does not. A rate is learned from at least 20
finished samples, else it is the Facility's default; a crew is learned from distinct operators per
hour, else it comes from
karyo.flow.crews. A stage with work and no crew is reported as not moving, never given an invented one. - Named "flow". The plain name "flow" says what the module computes, and it matches the routes
(
/api/v1/flow).
Consequences
- A projection is reproducible: the same rows and settings give the same facts, so two candidates compare on their decision alone.
- The readers name other modules' tables, columns and state codes directly. A rename breaks them at run time rather than at build time, as with every shared-schema reader.
- Karyo stamps no start or operator on receiving, packing and shipping work, so those stages run on default rates and need a configured crew. An installation that sets no crew sees them reported as not moving.
- The model leaves out reserve stock, cut-off times, dock appointments and shift rosters, and only the simulator walks, using layout's shared aisle and cross-aisle distances (the flow model).
- The simulator takes one immutable snapshot from
LocationDistanceLookup(ADR 0060), so the run reads no live rows and keeps no all-pairs matrix. It starts at the first Area's entry, uses walk metres for routing and timing, and reports lift metres separately without timing the lift. Walking requires a physical place for every located demand line; legacy grid steps are not metres. A line with no known location is left out of the sample and counted in the result's warnings. - The Locations floor view uses layout's resolved floor points and Area/Zone outlines. Each bay groups its levels by physical Area, Zone and Aisle identity, never by legacy grid coordinates.
- Changing the reorder simulator's default changes no figure on the Simulation page, because the scenario and the arithmetic replay agree; a test holds them equal.
Alternatives considered
- Grow it inside the Floor Assessment package. Rejected: that package reasons over monitor alerts and ships with the monitors engine, while this model reads every stage's work and must be usable as a library by a simulator.
- A separate simulator process with its own copy of the rules (Python, SimPy). Rejected: it would drift from Karyo's rules as they change. One Kotlin implementation serves both the projection and the simulator.
- Packing per order for wave orders, or the address rule copied into the reader. Rejected: the first overcounts packing for a consolidated group, the second gives the address rule a second home that would drift from the wave module's.
- A judgment model in the projection. Rejected: rates, queues, capacity and time are arithmetic, and the projection's facts must be reproducible.
Evidence
services/flow-service/karyo-flow-api/src/main/kotlin/com/karyo/flow/spi/Projection.kt,Projection- the seamservices/flow-service/karyo-flow-core/src/main/kotlin/com/karyo/flow/engine/FlowRun.kt,FlowRun- the deterministic runservices/flow-service/karyo-flow-core/src/main/kotlin/com/karyo/flow/service/FlowStateBuilder.kt,MIN_RATE_SAMPLES- learned rates and crewsservices/flow-service/karyo-flow-core/src/main/kotlin/com/karyo/flow/reader/FlowWorkReader.ktandFlowHistoryReader.kt- the shared-schema readsservices/forecasting-service/karyo-forecasting-api/src/main/kotlin/com/karyo/forecasting/spi/SkuForecastLookup.kt- the forecast seamservices/flow-service/karyo-flow-core/src/main/kotlin/com/karyo/flow/sim/DaySimulator.kt,PolicyComparison.kt,DayReplay.kt- the simulator, the comparison run and the replay with itsTOLERANCEservices/flow-service/karyo-flow-core/src/main/kotlin/com/karyo/flow/sim/ReorderScenario.kt- the reorder backtest on the engineservices/wave-service/karyo-wave-api/src/main/kotlin/com/karyo/wave/spi/ConsolidationMembershipLookup.kt- the consolidation seamservices/flow-service/karyo-flow-core/build.gradle.kts--apidependencies only
Related
- The flow model - what it reads, learns and states
- ADR 0006 - the module rule it keeps
- ADR 0011 - the shared-schema read it follows
- ADR 0060 - the shared distance service
- Floor Assessment - the alert-based view beside it