Karyo
Documentation/ Architecture

The warehouse flow model

Karyo 2.1.1rendered at build time
On this page

The flow model is a model of a distribution centre as flow stages with queues, people and rates, and a projection that runs that model forward in time. It is deterministic code: it calls no model and makes no decision. It answers one question: if the floor goes on as it is, or as a candidate changes it, what happens downstream by a given time? Its surfaces are read-only:

  • GET /api/v1/flow/state - every stage's open work, people and rate, and the forward bins in summary.
  • GET /api/v1/flow/projection?horizonMinutes=240 - the floor as it is staffed and dispatched now, run forward 1 to 1440 minutes, with the named facts the run produces.
  • GET /api/v1/flow/simulation?date=&seeds=5 - the day simulator's comparison of policies R, O and P over days sampled from the Facility's demand, one per seed (1 to 20), with the crew the Facility's history shows.
  • GET /api/v1/flow/replay?date= - a past day's own orders replayed through the model and held against what the day did; 404 when no order was created that day.
  • GET /api/v1/locations/floor - every location's physical place and resolved floor point, which the read-only Locations floor view draws with GET /api/v1/floor-plan.

The console calls only the last one. The reorder backtest on the Simulation page runs as a scenario of this model (below). Dates are ISO yyyy-MM-dd in the Facility's clock; the simulation defaults to today and the replay to yesterday.

The module is services/flow-service: karyo-flow-api holds the model types, the Outcome and the Projection SPI; karyo-flow-core holds the readers, the state builder, the built-in projection and the day simulator, which uses the projection's engine as a library. ADR 0058 records why it is a module of its own and why it is rule-based.

There are seven stages, from inbound to outbound, with counting as a side stage that borrows people (FlowStage). Each stage counts its work in one unit:

Stage Open work comes from One unit is
Receiving advice lines still to receive, on an advice expected today or with no date an advice line
Putaway open, unpaused transport orders other than replenishment (putaway, move, transfer, cross-dock) a transport order
Replenishment open, unpaused replenishment transport orders a transport order
Picking open picks, and open order lines that no pick serves yet a pick line
Packing shipments in packing a shipment
Shipping shipments packed or shipping a shipment
Counting generated count orders a count order

The links between stages are the ids the modules already share, and they act when work finishes:

  • a received advice line becomes a putaway;
  • a pick draws its forward bin down; a pick's bin is the fix assignment for its source stock unit's location and its product;
  • a bin below its minimum gets a replenishment, topped up as the scan does, when the replenishment scan runs on its own (karyo.replenishment.auto-scan-enabled): to its desired amount when it has one within its minimum and maximum, else to its maximum, and a bin with neither is topped up to its minimum;
  • a replenishment fills its bin;
  • the last open pick of a packing unit makes it ready to pack, and a packed unit is ready to ship.

A packing unit is a delivery order, or the consolidation group a released wave packs it with. A pick finds its delivery order through its own order line, so a wave batch pick counts toward its order, and the wave module names the order's group (ConsolidationMembershipLookup, by the same whole-address rule its READY guard uses). A group packs once and ships as all its orders. An open group shipment reads as packing or shipping work that carries its member orders.

A released pick already holds its stock, so it never waits for its bin. An open order line with no pick, and forecast demand, are not reserved: such a line starts only when its bin has the stock.

What the model learns, and what it falls back to

The model reads its Facility's own history over karyo.flow.history-days (default 28).

  • Rates. Units per person-hour, from finished work stamped with a start and a finish no more than eight hours apart: pick lines over pick orders' durations, transport orders and count orders over their own. A stage with at least 20 such samples uses the learned rate. Any other stage uses its default from karyo.flow.default-rates. Receiving, packing and shipping are always defaults, because Karyo stamps no start for that work.
  • Crews. Who works each stage: the mean number of distinct operators finishing the stage's work in a Facility-local hour that had any. karyo.flow.crews replaces the learned crew of every stage it names, and can give one crew several stages (PICKING,COUNTING=3). A stage with work and no crew does not move, and the projection says so.
  • Per-bin demand. The hard part is in the state: the released picks on a bin and the open order lines that will draw from it. The soft tail is the SKU's forecast from the forecasting engine (SkuForecastLookup, the same numbers as GET /api/v1/forecasts), spread over the SKU's bins by their share of its recent picks (evenly when no bin has history) and over the day by the Facility's hour-of-day profile of picked quantity. A forecast line arrives each time the cumulative forecast passes the bin's known demand by another typical line quantity.

A list setting that does not parse is skipped entry by entry, and the state lists each skipped entry in warnings.

The projection

The built-in projection (key queues, QueueProjection) runs the state as a discrete-event simulation (FlowRun). Time moves from event to event, and every tie is broken by a sequence number, so the same state, candidate and horizon always give the same outcome.

The floor is a pull model, as in Karyo: a person who is free takes the first unit of a stage they can work, in dispatch order, and works it for 1 / rate hours. The dispatch order is the Facility's own WorkDispatchStrategy bean, found by karyo.work.dispatch-strategy as /work/next finds it; a Facility that selected the position-aware PROXIMITY strategy counts only while karyo.proximity.enabled is on, and a candidate that names it is used as asked. A position-aware strategy orders the whole pool for each free person from the place of the unit that person finished last (the depot at the start, and again after a walking picker returns), measured on the state's floor. Packing and shipping are not in the work inbox, so they come after the inbox work, highest priority then oldest first. Work someone has already claimed stays with a person who can work its stage.

The run keeps each stage's waiting units ordered and adds or removes one unit at a time, so a day-long horizon does not re-sort the pool on every event. That needs the strategy to supply a comparator, as the built-in STRICT_PRIORITY and TRAVEL_PATH do. A strategy with only order still works, but the run re-sorts the whole pool through it each time the pool changes, so a long horizon over a large pool is slower. A pick that waits for its bin's stock leaves the queue until that bin is replenished.

A candidate changes the run: it can replace the crews, name another dispatch strategy, say how pickers walk, or give bins a reorder rule. The projection route runs the baseline only; the SPI, the simulator and the reorder scenario take other candidates.

The run's clock can be advanced in steps (FlowRun.advanceTo) and the floor read between them: the simulator records its hourly timeline that way, and the reorder scenario reads each day's closing stock.

The outcome has per-stage counts (open at the start, arrived, finished, open at the end, peak, when the starting backlog cleared), per-crew busy and idle person-minutes, and these facts:

Fact States
NO_CAPACITY a stage has work and no crew: "No crew works Putaway: 20 transport orders do not move"
BACKLOG_CLEARS the work open at the start is all done: "Putaway backlog of 6 transport orders clears by 08:15"
BACKLOG_AT_HORIZON open work at the end of the horizon
BIN_RUNS_DRY a forward bin reaches zero, or is empty now
PICKS_DELAYED pick lines that waited for their bin's stock, and their mean wait in minutes
ORDERS_SHIPPED delivery orders whose shipping finished within the horizon

Times are in the Facility's clock.

Walking pickers

Under the projection's own picking (SINGLE) a pick line takes 1 / rate hours, so the walking is inside the learned rate. The simulator's policies walk the floor instead (Candidate.picking): a picker leaves the depot, the first Area's entry in floor-plan order, with a cart, stops at each line's location for karyo.flow.pick-seconds-per-line (default 20), walks between stops at karyo.flow.walk-metres-per-minute (default 60), and returns. A cart holds at most karyo.flow.cart-lines (default 12). Layout's LocationDistanceLookup supplies an immutable snapshot of the physical hierarchy and distances (ADR 0060). Walk legs, nearest-neighbour routing and travel per line all use its walkMetres, through aisles and cross-aisles. The snapshot reads the rows once; advancing simulated time does no I/O and needs no all-pairs distance matrix. The run reports liftMetres separately in the picking stage, and the comparison reports lift metres per line without adding it to walking distance or time. Facility floor sizes and Area, Zone and Aisle overrides resolve in layout, with no flow-specific scale setting. An order line with no known location (not yet picked, with no fixed bin for its SKU, or picked from a stock unit since purged) is left out of the sample, and an order with no located line is left out with it; the result's warnings count both, in the comparison and in the replay alike. A line whose location has no physical place makes the comparison, whose policies walk, return 400 naming how many, instead of inventing distances from grid steps; the replay runs the baseline, which does not walk, so it needs no places.

Policy Dispatch A walk takes Route
R, Karyo's built-ins STRICT_PRIORITY one delivery order's lines, up to a cart in dispatch order
O, classic optimisation TRAVEL_PATH, over each location's walk order the first line's zone, filled with that zone's waiting lines nearest neighbour first
P, the live proximity rules PROXIMITY, per free picker one delivery order's lines, up to a cart nearest neighbour first, from stock taken by the same-day-nearest rule

Policy P is a what-if: it runs as if the Facility had switched proximity on and every strategy had opted in, whatever the Facility's karyo.proximity.enabled says, so a Facility that has proximity off can see what turning it on would do. It runs the production rules, not copies of them. PROXIMITY is the dispatch strategy live dispatch uses (ADR 0063). The route is the layout snapshot's route, which gives a live pick order its sequence and policy O its walk (ADR 0062). The stock a line is taken from is chosen by PickSourceOrder.SAME_DAY_NEAREST, the rule live stock selection applies, with the order's earlier lines as its anchors. As at release, each line takes its stock in order, and the walk then visits the places chosen nearest first. The rule has places to choose among only when the Facility's picks show them: for a SKU on a day, the places its picks drew from that day, each with the rotation date of the stock there. Stock with no rotation date never forms an interchangeable day, so on a Facility whose stock carries no date, as the demo's does, P keeps each line where it was picked. The TRAVEL_DISTANCE putaway sort does not enter the day: a day of picks puts nothing away, so putaway has no effect on the walk per line. The walk from the dock to the suggested bin is measured through the live finder in the release evidence instead.

The day simulator

DaySimulator runs one day on a fresh floor: the Facility's bins, crews, rates and locations with no open work. An arrival process brings the day's orders, and every line is a released pick that already holds its stock, as Karyo reserves an order at release, so the policy and not the stock decides the day. The clock advances an hour at a time and the run keeps an hourly timeline of the picking and packing queues.

  • Arrival process. SampledArrivals draws a day from the Facility's demand profile: for each Facility-local hour, a Poisson number of orders with that hour's mean over the history window, each a copy of one of the window's orders (the most recent 5,000) at a random second of the hour. The same seed always gives the same day. In the demo's open-demand profile the window's orders are the UCI Online Retail invoices, so a sampled day keeps their hour-of-day shape and line mix. ReplayedArrivals is a past day's orders as they came.
  • Comparison run. PolicyComparison runs the same sampled day, one per seed, under R, under O and under P, and summarises each metric per policy as a mean and a sample standard deviation: orders arrived, lines picked, lines not picked, orders shipped (when a crew packs and ships), lines per picker hour (walking included), metres walked per line, and separate lift metres per line. All three policies run with the same crew, the one in the baseline state.

Replaying a past day

GET /api/v1/flow/replay runs the orders created on a day, at the times they came, through the baseline (the installation's dispatch, each line timed by the learned rate) until a day after the day ends, and holds three measures against Karyo's rows: lines picked, picking person-hours (the finished pick orders that served the day's orders, each counted once), and orders shipped. The stated tolerance is 10%: each simulated measure within 10% of the actual one. The day is reproduced when every compared measure is. Orders shipped is compared only when a crew packs and ships; otherwise the replay names it as not compared. On the demo warehouse, whose history stamps who picked each order and for how long, a replayed day compares lines picked and picking hours.

The reorder scenario

The reorder backtest behind GET /api/v1/simulations/reorder and the Simulation page runs on this engine (ReorderScenario, key flow, the default of karyo.simulation.simulator). A SKU is one forward bin that opens at s + Q. Each day's demand arrives at noon as one line that takes what the bin has and loses the rest, as a lost sale. The reorder rule is the candidate: at or below s with nothing on order, order Q, which lands at the start of the day the lead time later. The run gives the page's numbers (stockout days, fill rate, average closing stock), equal to the arithmetic replay's, which stays selectable as lost-sales.

The floor view

The Locations page has a Floor view (/locations?view=floor) that draws every location at its plan position, shaded by how full the WMS reports it with the table's tones, each zone a tinted region named on the plan. The levels of one bay share one tile, framed in their combined state (blocked if any level is, else their mean fullness) and cut into one band for each level, which opens on its own; a bay taller than eight levels gets thinner bands rather than a larger plan. Locations outside aisles are no bay levels: several at one floor point (a zone's or an Area's entry, for dock doors and staging lanes with no rack data) are one dashed marker with their count, which lists them when opened, and they never set the plan's scale. Clicking a location opens it beside the plan. GET /api/v1/locations/floor supplies each location's stored place and resolved point in metres; GET /api/v1/floor-plan supplies the Area and Zone outlines. Bay groups use Area, Zone and Aisle identities, so coincident legacy grid steps in different zones never merge. A point at the origin is valid; only a missing physical place is omitted and reported. The demo seeds physical aisles and bays as well as its legacy grid steps.

Limits

  • Reserve stock is not modelled: every replenishment finds its source.
  • The projection does not walk: a rate learned from history already includes the walking. Only the simulator's policies walk, using layout's aisle and cross-aisle routes, without congestion.
  • Lift is a separate distance, not a simulated operation: no lift speed or forklift model is assumed.
  • Zone batching pays only when a zone has several waiting lines. At a light load, O walks each of an order's zones on its own and can walk further per line than R, as on the demo warehouse's handful of orders a day; the comparison states that rather than assuming O wins.
  • Policy P walks one delivery order at a time, as live pick orders do, so it does not batch across orders. Under a queue, O's zone batching walks far less per line than P (release evidence).
  • The simulator's pickers return to the depot after every cart, so PROXIMITY dispatch measures every pick from the depot. The operator position of ADR 0063 moves after putaway, replenishment and count work, which a simulated day of picks never generates.
  • A replay's picking hours are the day's lines at the learned rate, an average over the history window, so a day picked faster or slower than usual falls outside the tolerance and the replay says so.
  • There are no carrier cut-offs or dock appointments, because Karyo stores no cut-off time and no appointment, so no fact speaks of them and "orders shipped" is by the end of the run.
  • There are no shift rosters: a crew is there all day, and lines per picker hour counts the hours pickers spent on picking.
  • Karyo stamps no start or operator on receiving, packing or shipping, so those stages need karyo.flow.crews before they move.
  • The demo history stamps who picked each order and how long it took, so a demo warehouse learns its picking rate and crew; its other stages have no crew until the setting names one.
  • Nothing is cached: every state, projection, simulation or replay request reads the rows and learns the rates again. This is a known issue, kept on purpose: a cache would need rules for when its answer is too old, and the model has not needed them yet. What it costs is measured below.

What a request costs

The history the model learns from is what a request costs. Open work adds little: on a Facility holding 168,000 delivery orders, going from no open pick to 50,000 open picks moved state from 1.3 s to 1.6 s and projection from 1.8 s to 1.5 s, within the spread between runs.

These are the medians of single requests, one caller at a time, after two warm-up requests. The machine was an 8-core Ryzen 7 5800X3D with 16 threads, PostgreSQL 16 in a container on the same host and the application in quarkusDev. It is a development setup, so read the figures as a ratio, not as a capacity claim. The data is the demo Riverside Facility repeated: the first row is the demo itself, the others hold that history 10, 50, 200 and 1,000 times (how to take the figures). The demo history is 120 days; the model reads the last 28.

Delivery orders in the Facility state projection replay simulation (5 seeds)
841 (the demo) 17 ms 16 ms 26 ms 38 ms
8,410 55 ms 57 ms 87 ms 1.7 s
42,050 0.24 s 0.24 s 0.34 s 8.9 s
168,200 1.2 s 1.1 s 1.4 s 10.3 s
841,000 7.0 s 7.1 s not measured not measured
  • state and projection grow in step with the orders the Facility holds, at about 6 to 8 milliseconds for every 1,000 orders. They answer in under a quarter of a second up to about 42,000 orders, and in about a second at 168,000.
  • replay grows the same way: about 8 to 10 milliseconds for every 1,000 orders.
  • simulation costs more because it runs the day for each seed. These figures were taken with policies R and O; policy P adds a third run of each day. Its profile sample is capped at 5,000 orders (FlowSimulationService.MAX_PROFILE_ORDERS), so its cost stops rising at about 9 to 12 seconds once the 28 days hold more than that. Asking for the most seeds, 20, adds up to a quarter: 12.1 s against 10.3 s at 168,200 orders. The orders of the simulated day itself change little: days of 400 to 2,600 orders took 10.6 to 18 seconds on the 168,200-order Facility.
  • Two callers at once on each of the four routes (eight requests in flight) raised the medians by about half at 168,200 orders and doubled them at 841,000. The request thread does the whole computation, so a slow request holds one worker for its duration.

A Facility with some thousands of orders gets state, projection and replay in tens of milliseconds. One with over a hundred thousand waits seconds for each, so a screen that opens these routes should not refresh them on a timer.