Karyo
Documentation/ What Karyo does in a warehouse

Putaway and location finding

Karyo 2.1.1rendered at build time
On this page

Putaway is two mechanisms bolted together: a task lifecycle in the task module, and a placement algorithm in the layout module. They meet at one SPI call.

The trigger

TaskService.onGoodsReceiptLineReceived observes GoodsReceiptLineReceivedEvent (services/task-service/karyo-tasks-core/.../service/TaskService.kt, TaskService.onGoodsReceiptLineReceived) and creates one PUTAWAY transport order per received line. It runs at TransactionPhase.AFTER_SUCCESS in its own REQUIRES_NEW transaction, because the unit load and stock must be visible to the inventory lookup - which they are not until the receiving transaction commits (TaskService.onGoodsReceiptLineReceived).

Four conditions make it return early, in order:

  1. event.qaHold - held stock is not ready to put away (TaskService.onGoodsReceiptLineReceived). A held line gets this putaway when its hold is released, starting from where the unit load sits then.
  2. A cross-dock order already exists for the line. The cross-docking engine's interceptor runs synchronously inside the receiving transaction, so by the time this observer runs the lookup is authoritative. An unresolvable Instance<CrossDockLookup> means no lookup bean answered - treated as never intercepted (TaskService.onGoodsReceiptLineReceived).
  3. A task already exists for the line - idempotency, keyed on goodsReceiptLineId (TaskService.onGoodsReceiptLineReceived).
  4. The unit load cannot be found - logged at WARN and skipped (TaskService.onGoodsReceiptLineReceived).

The phase split between the two consumers of the same event is the interesting part, and it is the one architectural decision that shows up as functional behaviour: cross-dock must claim the line inside the receipt transaction so that putaway, running strictly after commit, can see the claim and stand down. Events and the outbox describes the mechanism; this is what it buys.

Auto-putaway is always on for non-held lines. It is hardcoded, not configurable, and the KDoc says so explicitly and names a future ReceivingStrategy as the place tunability would go (TaskService.onGoodsReceiptLineReceived).

Task creation, and what happens when there is nowhere to go

createPutawayTask (TaskService.createPutawayTask) persists the order, transitions it to CREATED, then asks the finder:

  • Found - the suggestion is stamped and the order goes to RELEASED, i.e. into the work queue.
  • NoLocation - the order stays CREATED with the reason in note, so the work is not lost (TaskService.createPutawayTask).

A CREATED transport order is not claimable: TaskService.assign requires RELEASED, and the work provider's claimable query filters on the same, so a putaway parked this way is not offered to the floor. The console lists these putaways under the Needs location chip of the Tasks board (GET /api/v1/transport-orders?state=50&type=PUTAWAY).

POST /api/v1/transport-orders/{id}/find-location (TaskService.findPutawayLocation) moves one on. It accepts only an unpaused PUTAWAY in CREATED, and runs the finder again with the order's persisted strategy (PutawayLocationSearch.reResolveSuggestion):

  • Found - the same order takes the suggestion and its reservation, its note is cleared, and it goes CREATED → RELEASED through TransportOrderEmitter.transition, so the journal and the outbox record an ordinary release. Its goodsReceiptLineId link stays.
  • NoLocation - the call answers 409 no-putaway-location with the finder's reason, and the order stays CREATED.

The Find location button on the task in the console calls it. No scheduler calls it: a person presses it after changing what blocked the search, such as a full bin, a missing location or a strategy's zone. Cancelling the task and raising a manual MOVE still works, but the move carries no receipt-line link.

start also runs the finder again when a PUTAWAY reaches it with no suggestion (TaskService.start):

if (order.transportType == TransportType.PUTAWAY && order.suggestedLocationId == null) {
    val result = putawaySearch.reResolveSuggestion(order)
    if (result is LocationFinderResult.NoLocation) {
        order.note = "No location suggested on start: ${result.reason}"
    }
}

TaskService.start

A released putaway always carries a suggestion, so this branch guards rather than serves a path in use. suggestedLocationId is never written back to null anywhere in the codebase, so the "or a since-gone one" half of the KDoc of start cannot fire either.

The finder

LocationFinderService plays two roles at once (.../layout/service/LocationFinderService.kt, LocationFinderService): it is the public LocationFinder facade, and it is the lowest-priority PutawayLocationStrategy, the built-in algorithm that runs last and always has an opinion.

The facade runs the strategy chain in ascending priority and takes the first non-null result (LocationFinderService.findPutawayLocation). A custom strategy at any lower priority pre-empts the built-in entirely, and owns its own reservation semantics.

The fourteen filters

The full list is in the class KDoc (LocationFinderService).

Six run as SQL predicates in one query (StorageLocationRepository.findPutawayCandidates):

l.lockType = 0
and l.allocation < 100
and l.allocationState = 0
and not exists (select 1 from FixAssignment f where f.location = l)
and a.usages like :usage
and (t.liftingCapacity is null or t.liftingCapacity >= :weight)

plus the zone predicate (the zone) and the Facility predicate (l.facilityId = :facilityId: the finder searches the one Facility it is given, so a sibling Facility's locations are never candidates), ordered allocation asc, name asc.

Filter 5 also runs a batched in-service check before the finder reserves a location. It reads the committed weight of the capped candidates in the requested Facility through CommittedWeightReader: the gross weight resting there (StockUnitLookup.grossWeightByLocationIds) plus the weight of the open reservations for the location (LocationReservation.weight). Committed plus incoming weight must not exceed the cap, with equality allowed. Only null is unlimited; zero permits only zero total weight. This agrees with LocationService.checkCapacity, which reads the same committed weight. Unweighed loads and their reservations contribute zero. Reservations of the order being searched for are left out, so a re-search does not count the pallet against itself. Stock changes after the search are not covered.

The other in-service checks over the SQL survivors are also batched: active-reservation fold, TypeCapacityConstraint compatibility and capacity, StorageArea restriction and FIFO/full-area hiding, field/section group lifting capacity, and the occupancy-plus-in-flight-transport mixing pass (item only: a Facility has one owner, so there is no client occupancy to compare).

Two of these deserve emphasis because they change results silently.

No configured areas means no restriction at all. If the resolved strategy has no StorageStrategyArea rows, filter 9 imposes nothing. That is deliberate: requiring locationCluster IS NOT NULL instead "would silently exclude every cluster-less location in an existing deployment" (LocationFinderService).

Filter 5 counts what is already there and what is on its way. The SQL predicate compares the type's cap against the incoming weight alone; the in-service check above then adds the committed weight at the location: the weight resting there plus the weight of pallets reserved for it that have not landed. A bin with a 1000 kg cap that holds 600 kg is therefore offered to two 200 kg pallets of one goods receipt, and the third is sent elsewhere, because each search sees the reservations the earlier searches wrote. The field/section group rollups (filter 10) add the same committed weight across a field or section, and only where the location type defines those columns.

Ordering, and who gets the last word

Default order is effective allocation ascending (emptiest first), then location name ascending as a stable tie-break. strategy.sorts and nearPickingLocation layer a typed comparator chain on top, and useAreaStrategyDate prepends the strategy's area order (LocationFinderService, CandidateOrdering). An empty sorts with nearPickingLocation off leaves the default order exactly as it is; the KDoc of CandidateOrdering pins this.

Travel distance. The sort key TRAVEL_DISTANCE (code 9) ranks a candidate by the walk from where the unit load stands: the request's originLocationId, which auto-putaway fills with the unit load's location (PutawayLocationSearch). The walk is the aisle-based walk in metres of the one distance service (ADR 0060), and the lift in metres breaks a tie. Grid steps play no part: two bins back to back in neighbouring aisles are as far apart as the walk round the aisle end. A strategy lists the key where it wants it in sorts. The keys before it win over the walk, and the keys after it break walk ties (ADR 0061).

A candidate is measured only when the Facility's proximity setting is on (Proximity in the Facility) and the candidate has a place on the floor (PutawayTravel). The measured candidates come first, nearest first. The others follow in the order the rest of the strategy gives them. When TRAVEL_DISTANCE is the strategy's only key and nearPickingLocation is off, the rest of the strategy is nothing, so the unmeasured candidates keep the default order. A search with the setting off, with no origin, or with an origin with no place therefore gets the suggestion the default order gives (CandidateOrdering.apply).

Near the pick face. nearPickingLocation ranks by the walk from the product's pick face (its FixAssignment with the lowest orderIndex), with the lift as the tie-break, ahead of every other key (CandidateOrdering.nearPickingComparator), when the Facility's proximity setting is on. It measures the same candidates that TRAVEL_DISTANCE measures. Candidates with the same walk and lift, such as the bins of one zone that stand in no aisle, and the candidates it cannot measure, follow in the grid order it used before: the pick face's rack first, then the fewest X steps from the pick face. A pick face with no place, or a Facility with the setting off, uses that grid order for every candidate.

Then the SPI LocationFilter chain runs, and its order is honoured verbatim: the finder takes first() and does not re-sort (LocationFinderService, LocationFinderService.resolveViaSpiFilters). Stock selection honours its own filter chain's order the same way, so both seams behave alike.

Proximity in the Facility

Proximity is one setting of the Facility: karyo.proximity.enabled, a Boolean runtime setting that is false until an administrator sets it (Admin > System properties, FloorPlanService.proximityEnabled; ADR 0061). Each proximity function reads it independently. Turning it on also makes the product's Facility zone the putaway zone, ahead of the strategy's zone, for every product that has one (the zone), so a product's zone can be cleared first (empty the Zone field of the product form, or send zoneId as null in the product update). A product zone that no longer exists in the Facility is ignored. The Areas page shows the Facility's zone distance table when the setting is on. Karyo computes the walk between each pair of zone doors from the layout. A layout administrator can correct it where the building differs, or clear a correction to restore the current computed value (console instructions). The correction is symmetric and replaces only the cross-zone leg; travel inside each zone stays computed. FloorPlanService supplies that effective distance to putaway, proximity pick routes, the distance API and flow snapshots. A changed correction can therefore change the nearest bin, without changing filters or local travel.

Ranking by walk metres still needs the function's own strategy to ask for proximity:

  • Putaway ranks by distance when the setting is on and the storage strategy lists TRAVEL_DISTANCE. nearPickingLocation ranks by the walk to the pick face when the setting is on.
  • The pick route walks a pick order's picks nearest neighbour when the order strategy sets proximityRoute (Picking).
  • Task interleaving offers the nearest work to where the operator stands when the Facility's karyo.work.dispatch-strategy is PROXIMITY (Work allocation).
  • Pick source is not built yet. It will opt in through its own strategy configuration when the setting is on.

When the setting is off, TRAVEL_DISTANCE and nearPickingLocation rank as they did before proximity putaway, for every candidate: TRAVEL_DISTANCE ranks nothing and nearPickingLocation keeps its grid order. When it is on, every candidate with a place on the floor is measured, in whatever Area it stands; no Area is skipped or ranked after another. The seeded Facility default strategy lists TRAVEL_DISTANCE, so it has no effect until the setting is on.

Strategy resolution

Three rungs, in order (LocationFinderService.resolveStrategy):

  1. the request's storageStrategyId - for auto-putaway, the receipt line's validated per-line override, persisted on the transport order so a later re-resolve replays it;
  2. the incoming product's defaultStorageStrategyId;
  3. the Facility default strategy (StorageStrategyService.facilityDefault).

The Facility default is the one storage strategy of the Facility with facilityDefault = true; a unique index allows one for each Facility. Layout V1608 seeded one for each active Facility. It is named Facility default, or Facility default (travel distance) where the shorter name was taken. Its sorts is TRAVEL_DISTANCE, and every other field has its default: mixItem = true, no zone, and no other flag. A Facility created later gets the same strategy from its Warehouse setup or from its first putaway search, by the same insert-if-absent (StorageStrategyRepository.insertFacilityDefault). An administrator edits it like any other strategy, and, like any other, it cannot be deleted.

Whichever rung produces the id, the strategy must belong to the Facility being searched (StorageStrategyRepository.findInFacility). A strategy of another Facility, or a missing one, resolves to the Facility default. The reasoning is spelled out: without the check, naming or inheriting another Facility's strategy would apply that Facility's rules and borrow its zone.

Only a Facility that is not active has no default. Its search runs with no strategy: mixItem = true and no zone. There is no shared location to opt into: every location belongs to a Facility.

The zone

The zone predicate takes the first zone it finds, in this order (LocationFinderService.tryFindPutawayLocation):

  1. the request's preferredZoneId. A receipt line has no zone of its own, so auto-putaway does not set it;
  2. the incoming product's zone in the Facility (ProductFacilityPolicyRef.zoneId), only while the Facility's karyo.proximity.enabled setting is on and only if that zone still exists in the Facility; otherwise this rung is skipped;
  3. the resolved strategy's zone.

The same zone starts the overflow chain that the ZONE sort key ranks by (CandidateOrdering.zoneChainRank).

manualSearch

A strategy with manualSearch = true short-circuits the entire search before any candidate query is built, returning NoLocation with a reason (LocationFinderService.manualSearchResult). The task module's "keep the work" fallback is then the manual placement flow. The same flag also bypasses findAddToLocation (LocationFinderService.findAddToLocation).

Soft reservations

A Found result writes a LocationReservation row so two concurrent putaways are never handed the same nearly-full location (LocationFinderService.reserve):

  • key - the transport order id, so the caller can release by the same key;
  • unit load - the unit load the reservation holds the location for (LocationReservation.unitLoadId);
  • load - percent = the allocation percent of the matching TypeCapacityConstraint row for the (location type, unit-load type) pair, 100 when no row matches;
  • weight - the unit load's gross weight when the reservation was written, zero when unknown. It counts toward the location type's lifting capacity while the reservation is open;
  • TTL - 10 minutes, renewed for as long as the transport order is open (see below).

The percent is the same one a landed unit load will be charged (LocationAllocationService), so the capacity model honours the setting: 50 means one in-flight tote holds half a bin and a second putaway can still be handed the other half; two reservations jointly reach 100 and the location is full. A 100%-or-unrestricted unit load still fully reserves a location alone, and is only offered a location that is completely empty: a load with no matching row, including every load in a location type with no rows, is charged 100, so filter 7 never lets it land on top of what is already there (CapacityVerdict).

Effective allocation is location.allocation + Σ(percent of the reservations that count), and filter 3 drops anything at or above 100. So concurrent putaways admit exactly as many loads as fit.

A reservation counts a pallet that is on its way, never one that has arrived. While the unit load of a reservation rests at the reserved location, the reservation counts neither its percent nor its weight (OpenReservationReader): the pallet is counted there once, as resting weight and as stored allocation. This is the case after a hand transfer (POST /api/v1/unit-loads/{id}/transfer, or onto a carrier standing there) straight into the suggested bin while the task stays open. Nothing is released and the order is not touched. If the pallet leaves the bin again while the task is open, the reservation counts again at once, so the bin stays guarded against the task that is still to complete. A hand transfer to any other location changes nothing, because the open task still carries the pallet to its suggestion and its reservation keeps counting there.

Every stored unit load is charged its own percent when it lands (transfer in, the create-only transfer of a partial confirm, revive) and released for exactly that percent when it leaves (transfer out, trash) - the location's allocation is always re-derived as the sum of its current contents' percents, so an operator editing or deleting a constraint row while loads are stored only affects future placements, and a release never subtracts a different amount than the charge added.

A reservation lives for as long as its transport order is open, and ends two ways. A task complete or cancel releases it explicitly (TaskService.complete, TaskService.cancel). The 60-second sweeper (LocationFinderService.sweepExpiredReservations) otherwise decides by the order. For each reservation that expires within two minutes it asks the tasks module, through TransportDemandLookup.openTransportOrderIds, whether the order is still open, meaning not FINISHED or CANCELED. If it is, the sweeper sets expiresAt to ten minutes from now, so an unstarted, claimed or paused putaway keeps its percent and its weight counting however long it waits. If the order is closed or no longer exists, the reservation is left to expire and is reaped once expiresAt has passed, so a crashed or abandoned putaway never permanently blocks a location.

A released, completed, cancelled or expired reservation stops counting, for its percent and for its weight. A pallet that landed counts as resting weight from then on. The 10 minutes are therefore the bound for a reservation that nothing releases and that no open order owns; they are not a limit on how long a task may wait.

Pausing a task keeps its operator, its suggestion and its reservation. Resume finds the slot again however long the pause lasted (the KDoc of TaskService.pause). The same holds for area replenishment (the KDoc of TaskService.createAreaReplenishment).

Candidate paging

The finder reads its SQL candidates a page of 200 rows at a time (PutawayCandidatePages.PAGE_SIZE), and the in-service passes run on one page (LocationFinderService.placeFromPage). When they exclude every row of the page - a strategy's area restriction, a type-capacity constraint, lifting capacity, item mixing, or an SPI filter - the finder reads the next page, until a location survives or the query has no more rows (LocationFinderService.findCandidateLocation). When no page yields a location, the NoLocation reason is the first page's.

The page order depends on whether a walk leads the ranking (CandidateOrdering.leadingWalk):

  • No walk leads. The pages come in the query's order: base allocation, then name, then id (StorageLocationRepository.findPutawayCandidates). The first page holds the emptiest locations.
  • A walk leads. That is the walk from the pick face when nearPickingLocation measures one, or else the walk from the origin when TRAVEL_DISTANCE is the strategy's first key and no area order comes before it. One light query reads the place of every candidate (StorageLocationRepository.findPutawayCandidatePlaces), the finder measures each walk from its one floor read, and the pages come nearest first (StorageLocationRepository.findPutawayCandidatesByIds). The candidates it cannot measure follow in the query's order. So the nearest qualifying bin is found however many emptier bins the query would put ahead of it.

Each page is ranked on its own by the whole strategy, so a key that does not lead ranks the rows of the page that produced the winner, not every candidate in the Facility. In a Facility where nothing fits, one search reads every candidate row, 200 at a time, with the batched in-service reads once per page. Why the page size is 200 is not recorded.

What a walk costs. A search reads the floor once, however many pages it reads (FloorPlanService.plan). The cost was measured on the development machine, on one Facility of 5,000 placed bins that Warehouse setup created (aisles A to J, 50 bays, 5 levels, 2 positions), with every bin free. Each figure is the median of 30 searches after 5 warm-up searches:

Search Median 90th percentile
A strategy with no sort key, so no walk 43 ms 46 ms
TRAVEL_DISTANCE from a dock at the end of aisle J 82 ms 86 ms

Of the 39 ms more, the query for the 5,000 places takes about 35 ms and the floor read about 4 ms. The search with the walk suggested J-50-1-2, the bin next to the dock; the search without it suggested A-01-1-1, the first name.

The rest of the transport-order lifecycle

Putaway shares its entity, TransportOrder, with four other transport types (karyo-tasks-api/.../vo/TransportType.kt, TransportType): MOVE (ad-hoc operator move), REPLENISH, TRANSFER (a multi-hop chain successor) and CROSS_DOCK. They share one state machine, one work provider and one order-number sequence - the prefixes TO/MV/RP/XD vary, the sequence name does not (TaskService.generateOrderNumber).

CREATED → RELEASED → RESERVED → STARTED → FINISHED, plus CANCELED pre-STARTED. RESERVED → RELEASED (giving the task back) is the one backward move, and it is done by writing the field directly and re-emitting the event, because TransportOrderEmitter.transition is forward-only and would refuse it. The bypass is deliberate and documented at the site (TaskService.release).

pause is orthogonal to state: it stamps pausedAt and state never moves (TaskService.pause). The window is every pre-terminal state, wider than the goods receipt's, because the queue-and-claim lifecycle has two parking points - RELEASED (queued) and RESERVED (claimed, not started). The KDoc also records a deliberate observability gap: no event and no outbox row is written on pause or resume, even though every state transition streams to the outbox, "because pause is orthogonal to state by design and was never meant to appear in that stream" (TaskService.pause).

Cancel is deliberately not pause-guarded, unlike assign/start/complete: "pause is an operator's 'step away', not a lock against the task being pulled from the queue entirely" (TaskService.cancel).

complete has four shapes (TaskService.complete): whole unit load to the suggested or an overridden location; confirm-merge onto an existing unit load; a partial confirm; and, mid-complete, a possible TRANSFER chain successor if the destination is a transfer-staging area and the order still carries a different real target. The two destination shapes are mutually exclusive - both supplied is a 400.