ADR 0036: Warehouse setup reads labels on the server and creates them in one owner-targeted transaction
Status: Accepted. The owner target, global labels and installation-wide arrangement below are superseded by ADR 0040 and ADR 0048.
Current setup names targetFacilityId and requires layout.write on that Facility. The selected console context can fill the visible Facility field.
Locations, configuration, arrangement and idempotency runs remain inside the named Facility. An archived Facility or inactive Business Unit refuses creation.
See Set up a warehouse for the current flow. The original decision below records the earlier owner-targeted design.
Context
A customer who brings a warehouse to Karyo already has a labelling scheme: the first and last label
of each stretch of racking, or a list of names exported from another system. Creating those
locations one at a time through New location is the slow path the design round measured: 1,386
locations took about 10 to 18 hours by hand, and 61,304 took about 430 to 796 hours. The captain asked for
a way for customers to create their own DC that is "simple and fast so its not an overhead", and
took both recommendations of the design round ("Your recommendations are sick !"): setup from
location labels with the type-the-labels and bring-your-list doors first, and arranging the floor
built with it.
Four properties bind the design:
- A location name is globally unique across every goods owner (warehouse layout configuration), so a plan can collide with a label another owner already holds.
- Zones, areas and location types are instance-wide, while a location belongs to exactly one goods owner.
- A create of tens of thousands of rows must be all-or-nothing, and a lost response must be safe to retry.
- The drawing on Home is derived from addresses (
rack,field,xPos,yPos,zPos) and has no building footprint to read; nothing may present it as measured.
Decision
- The labels are the source, and the server reads them. The customer gives, per stretch, a zone, a use, a storage kind, the first and last label, and one side or both. The server splits each label at every letter-to-digit change, reads the segments as aisle, bay, level and position (a leading zone role from five segments up), counts letters A to Z then AA, keeps digit padding, and expands the range with the first part changing slowest. A pasted list is read into the ranges and stand-alone places that reproduce exactly the distinct names pasted; the reader refuses to return a plan whose expansion differs from the names read. The console holds no copy of this reader: it shows what the server read.
- Two doors first, one plan. Typing the labels and bringing a list produce the same plan, and the
same three-mode route serves both:
PREVIEWreads and draws and touches no table,CHECKreads what the installation holds and writes nothing,CREATEwrites. Picking an example, walking and scanning a building, tracing a building drawing, bulk label printing and per-storage-kind capacity are not in this change and are not drawn as disabled controls. - The goods owner is chosen explicitly, with no default. The captain's answer was "An explicit
choice each time, with no default". Every
CHECKandCREATEcarriestargetClientId. An OPS principal may name any active goods owner or Shared (client0); an OWNER principal may name only its own. A missing, inactive or forbidden target is refused with its own problem slug. The server is the authority and the page only mirrors it. - A create is one transaction under an idempotency key.
CREATElocks the single arrangement row, so setup calls serialize, then looks the key up before reading any label. The same key and the same normalized plan return the stored result withreplayed: trueand write nothing; the same key with a different plan is a 409; a new key for a plan already created finds every label owned by the target and writes nothing. New zones, areas, location types and locations are inserted in prepared batches inside the one transaction and the result is recorded inwarehouse_setup_runsin it, so a failure rolls all of it back. Splitting the commits was rejected because it would give up all-or-nothing. - The label lookups are planned with their own values. Finding which labels already exist sends up
to 1,000 bound names per query. A generic plan that Postgres reuses for that statement cannot hash
the list: on 61,304 stored locations it took about 1.5 s a query against 12 ms when planned with the
values, and the 62 queries of a repeat of a finished create outlasted the 60 s transaction limit
(a 500, or a 504 through the proxy) in three of six timing runs. Create and Check therefore set
plan_cache_modetoforce_custom_planfor their own transaction only. An index onupper(name)was considered and left out: it would add a migration to a large table for no need. - Existing rows are never rewritten. A label already owned by the target is reported unchanged. A label owned by anyone else refuses the whole plan with a generic 409 that names no label and no owner. A zone or location type that already has the name is reused as it is; an area is reused only when its usages are exactly those the use needs, and otherwise the plan is refused rather than silently changing shared configuration.
- The arrangement is installation-wide. The flow of goods (automatic, in and out on one side, in
at one end and out at the other, adjacent walls) and the inbound and outbound dock-door counts (0 to
- live in one row of
warehouse_arrangements, with noclient_id, like the zones, areas and location types they lay out. It is read with eitherinventory-readorlayout-read, saved withlayout-writeunder an optimistic version check, and applied to the drawing and the opened 3D view only. Doors are presentation and are never written back to locations.
- live in one row of
- The plan is bounded. A plan of more than 100,000 locations, or a pasted list of more than 100,000 rows, is refused before any write. A reason for that number is not recorded. The only measured scale is the timing run in the pull request: 61,304 locations created in about 12 seconds on the reference development machine.
Consequences
- A customer can set up a small DC in minutes instead of hours of form-filling, and the pasted-list door can bring a large existing list in without inventing or dropping a name.
- Because location names are global, a plan can be refused for labels another owner holds, and the refusal cannot say which. An administrator has to review ownership.
- Setup writes shared configuration by fixed names (
Storage,Picking,Receiving,Packing,Shipping,Pallet position,Shelf bin,Floor position,Staging lane). An installation whose area of the same name has other usages cannot use that use through setup until the area is changed. - The arrangement is one building for the whole installation. Two owners cannot draw different floors.
- The drawing stays an arrangement of addresses, not a floor plan; the page and the guide say so.
POST /api/v1/demo/resetclearswarehouse_setup_runs, so a reset demo replays no old create. It does not delete the onewarehouse_arrangementsrow: every create locks that row and a missing row is refused assetup-changed. It puts the row back to the automatic flow with no doors and moves its version on, so a console that still holds the old arrangement is refused as changed. Nothing else removes a setup-run row.- Reaching the Arrange step is through Done, after a create; an installation whose labels all exist cannot open it from setup again.
Alternatives considered
- Create locations one request at a time from the console. Rejected: the measured baseline was 124 seconds for 61,304 locations and, more to the point, no all-or-nothing outcome and no safe retry.
- Read the labels in the browser. Rejected: the browser would then hold a second copy of the reader, and the server, which creates the rows, is the only reader that can be relied on. The console shows what the server read.
- Default the goods owner to the caller. Rejected by the captain: an OPS caller acts for many owners, and the answer was to choose explicitly each time.
- Trace a building drawing, or walk and scan the building, as the first door. Deferred by the captain's choice of the label doors first; the reasons for each deferral beyond that choice are not recorded.
- Store an arrangement per goods owner. Rejected: one installation is one building (warehouse layout configuration), and the layout it arranges carries no owner.
Evidence
services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/api/v1/WarehouseSetupResource.kt,WarehouseSetupResourceplan,readList,getArrangementandsaveArrangement, the four routes
services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/WarehouseSetupService.kt,WarehouseSetupServicecreate, one@Transactionalunit, with a per-Facility lock throughWarehouseArrangementRepository.lockedForFacilityand an idempotency lookup throughWarehouseSetupRunRepository.findByKey;resolveTarget, the explicit Facility target
services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/repository/WarehouseSetupRepository.ktplanWithBoundValues, and theexistingLabelsandactualPositionslookups it protects
services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/WarehouseLabelReader.kt,WarehouseLabelReader.readListreadListandreadRange
services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/WarehouseSetupCatalog.kt- the fixed area, location-type and kind defaults
services/karyo-app/src/main/resources/db/migration/layout/V320__warehouse_setup_and_arrangement.sql- the two tables and their constraints
services/demo-service/karyo-demo/src/main/kotlin/com/karyo/demo/service/DemoDataService.ktreset, which truncates the runs and restores the arrangement row in place
tests/e2e/tests/warehouse-setup.spec.tsandtests/e2e/scripts/time-warehouse-setup.ts- the real-stack flows and the scale run
Related
- ADR 0035 - how a later setup extends an aisle that already holds locations
- ADR 0007 - other modules' rows are referenced by id
- ADR 0014 and ADR 0015 - goods owners and the OWNER and OPS principals the target rule uses
- Set up a warehouse - what the customer sees