ADR 0018: Tunable behaviour is strategy-driven, through a family of patterns rather than one rule
Status: Accepted
Context
Karyo has to work with nothing configured, and still let a deployment tune how stock is chosen, where it is put away, how short picks and pack-out are handled, how work is dispatched and how documents are numbered - and let an implementer replace a behaviour without forking the source.
Some of those knobs are values an administrator sets. Others are algorithms only code can express. Some are properties of the whole warehouse; some belong to one goods owner (ADR 0014).
Decision
Tunable behaviour is expressed as a default plus a knob, through four mechanisms. Each exists for a different kind of knob, and each has its own scope and selection rule.
- Named strategy entities, edited by an administrator.
OrderStrategy- instance-wide (no owner), unique name, typed columns for reservation, picking, short-pick, pack-out and progression behaviour, and a JSONBextension_propertiesmap. ADEFAULTrow is seeded by migration. An order names its strategy by id;OrderStrategyResolverbeans are consulted in ascending priority, the first non-null name wins, and the built-in resolver sits last and falls back toDEFAULT.StorageStrategy- per goods owner, bound to a product (or named by the putaway request). There is no seeded default; with none bound, putaway runs on the finder's built-in constants. (ADR 0061 later adds a seeded Facility default strategy, which changes nothing until the Facility's proximity setting is on.)
- The runtime property store (
system_properties), resolved per key through a ladder: the owner's row, then the instance-wide row for owner0, then the MicroProfile configuration value, then the caller's default. A code-owned catalogue gives known keys a type, group, description and default, and two flags:secretmasks the value in every read, andownerWritable = falsekeeps a goods owner from overriding an operator's hard stop. - MicroProfile configuration (
karyo.*inapplication.yaml, overridable by environment variable) for instance-wide knobs read at start-up. - CDI strategy beans for behaviour, compiled into the build
(ADR 0019). Selection is decided per seam:
- filter chains - every implementation runs in ascending priority and its order is honoured
(
StockSelectionFilter,LocationFilter); - first non-null wins, built-in registered at
Int.MAX_VALUEso it runs last (PutawayLocationStrategy,OrderStrategyResolver); - named match first, then ascending priority (
PackoutStrategy,ReplenishmentStrategy);CarrierAdapterclaims by carrier name; - selected by name, where an unknown name is a hard failure (
WorkDispatchStrategyat dispatch,SequenceNumberGeneratorat start-up,CountScopeStrategyper request); - direct CDI injection with no priority at all (
WebhookSigner,DeliveryRetryPolicy).
- filter chains - every implementation runs in ascending priority and its order is honoured
(
New knobs are placed deliberately: a stable, commonly used value is a typed field; long-tail or experimental configuration is a JSONB key; new behaviour is a strategy bean.
Consequences
- An installation that configures nothing gets coherent behaviour: the
DEFAULTorder strategy always resolves, and every built-in strategy sits behind any custom one. - Administrators tune by data without a redeploy; implementers extend by code.
- There is no universal selection rule. An implementer has to read each seam's resolver to know how a bean wins, and the same word, "priority", means activation in one place and chain order in another.
- Scope differs by mechanism.
OrderStrategyis instance-wide, so one holder oforder-writechanges order handling for every goods owner, whileStorageStrategyis per owner.OrderStrategyContextcarries the order's Facility and the built-in resolver ignores it. Why order strategy is instance-wide while every other strategy entity is per owner is not recorded. - Name validation differs. The name-selected seams fail loudly; the free-text strategy names on
OrderStrategy(short-fall, pick difference, pack-out) are validated by nothing and fall through to the priority chain, so a typo can quietly select a different strategy than the one intended. - The JSONB map retains fourteen Karyo-owned wave and streaming keys, validated on write with
their enum parsers, numeric bounds and registered strategy names. Every other key must start
with
ext.. Existing maps keep their runtime behaviour until a write sends a replacement; no row is rewritten.StorageStrategyhas no such map. - System-property writes accept catalogued keys or the
ext.namespace only. Existing unknown rows remain readable, identified by null type metadata, and removable. The console marks them Not recognised. Extension authors own the behaviour and validation ofext.values; this namespace does not turn a deployment-only Karyo setting into a runtime setting. - Neither strategy entity can be deleted, so a strategy id a product holds cannot go stale by
deletion. A mistyped id is refused when the product's Facility policy is written (422
invalid-configuration,ProductFacilityPolicyService.apply). - Most
karyo.*knobs have not moved onto the runtime store and remain instance-wide and restart-only. Whether they were assessed and kept there is not recorded.
Alternatives considered
- One unified configuration object. Rejected. It becomes unwieldy; per-domain strategies group related knobs and bind to different operations.
- Configuration by code only. Rejected. Operators could not tune anything without a rebuild and a redeploy.
- A rules engine binding strategies by order type, priority or wave, built up front. Rejected as premature. The resolver seam takes an operation context, so new inputs can be added later without changing the strategy entities or breaking existing resolvers.
- One priority-and-first-non-null rule for every seam. Not what the code does, and deliberately so where it matters: priority selection let a custom bean silently displace a default, so work dispatch, numbering and count scope select by name and refuse an unknown one. An unnamed count-scope resolve would otherwise escalate a targeted cycle count into a warehouse-wide freeze.
Evidence
services/order-service/karyo-orders-core/src/main/kotlin/com/karyo/orders/domain/model/OrderStrategy.kt,OrderStrategy- instance-wide, unique name, the JSONB relief valve,DEFAULTservices/karyo-app/src/main/resources/db/migration/orders/V405__seed_default_order_strategy.sql- the seededDEFAULTservices/order-service/karyo-orders-api/src/main/kotlin/com/karyo/orders/spi/OrderStrategyResolver.kt,OrderStrategyResolver- the binding seam and its contextservices/order-service/karyo-orders-core/src/main/kotlin/com/karyo/orders/service/DefaultOrderStrategyResolver.kt,DefaultOrderStrategyResolver- the built-in resolver and its fallbackservices/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/domain/model/StorageStrategy.kt,StorageStrategy- storage strategy per goods ownerservices/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/config/SystemPropertyService.kt,SystemPropertyService- the resolution ladderservices/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/config/SystemPropertyCatalog.kt,SystemPropertyCatalog-secret,ownerWritable, and non-catalogue keysservices/warehouse-layout-service/karyo-layout-api/src/main/kotlin/com/karyo/layout/spi/PutawayLocationStrategy.kt,PutawayLocationStrategy- first non-null wins, built-in lastservices/fulfillment-service/karyo-fulfillment-core/src/main/kotlin/com/karyo/fulfillment/service/PackoutStrategyResolver.kt,PackoutStrategyResolver- named match, then the priority chainservices/stocktaking-service/karyo-stocktaking-core/src/main/kotlin/com/karyo/stocktaking/service/CountScopeStrategyResolver.kt,CountScopeStrategyResolver- selection by name, and whyservices/karyo-app/src/main/resources/application.yaml,karyo.work.dispatch-strategy, karyo.sequence.generator- dispatch and numbering selected by nameservices/work-service/karyo-work-core/src/main/kotlin/com/karyo/work/service/WorkDispatchService.kt,WorkDispatchService.validateOnStartupandlibs/karyo-sequence/src/main/kotlin/com/karyo/sequence/SequenceNumberService.kt,SequenceNumberService.validateOnStartup- unknown names refused
Related
- ADR 0014 - goods owners, and which configuration follows them
- ADR 0019 - how a strategy bean reaches an installation
- Strategies and policies - the two strategy entities in full
- Runtime configuration store - the property ladder and catalogue
- Strategies and runtime configuration - the same mechanisms from an implementer's side