0047. An order is promised against its own fulfillment site
Status
Accepted — implemented by the change that introduces this record.
Amends ADR 0044
(the order's site was used for demand projection only),
ADR 0014 step A (every promise
used one configured site, DEFAULT_SITE_ID) and
ADR 0031 §5 (the annotation
matched one configured site). ADR 0044's rule is kept unchanged: the site is
assigned by the caller, never inferred or looked up.
Context
ADR 0014 step A computed every promise against ONE site: order.PromisePolicy.SiteId,
wired from DEFAULT_SITE_ID (default site-1) in cmd/order/outbound.go, passed to
every ScheduleSource.NextCutoffs call in promise_policy.go (Promise,
FeasibleBy, promiseForLines). ADR 0031's planned-capacity annotation reused the
same one-site assumption through PLANNED_CAPACITY_SITE_ID (defaulting to
DEFAULT_SITE_ID). Both ADRs named the missing order site as the gap.
ADR 0044 then gave the order an optional, immutable, caller-assigned
fulfillmentSiteId — but only the site/SKU demand projection read it.
That left a real collision in the running fleet. site-1 is the network-connected
building the storefront sells from. The warehouse-day simulator (e2e-tests) runs its
own building, SIM1, with compressed UTC cutoffs; because every order was promised
against site-1, the simulator had to PUT its compressed CPT schedule onto site-1
to get capability-based promises at all, and every simulator run overwrote the
storefront's real cutoffs and promises.
Alternatives considered:
- A second order-management deployment per site. Rejected: one service already
holds every site's CPT schedule (the
kafkacptschedulecache is keyed bysite_id); duplicating the deployment to change one string per order is cost without a decision. - Infer the site from the reservation or the SKU. Rejected by ADR 0044 §2: no sourcing logic belongs here.
- Make the promise site a request parameter separate from
fulfillmentSiteId. Rejected: two site fields on one order could disagree, and the promise and the demand projection would then name different buildings for the same order.
Decision
-
The promise reads the order's own site. One domain rule,
order.PromiseSiteFor(o, defaultSite): the order'sFulfillmentSiteID()when set, elsedefaultSite.PromisePolicyresolves it per call, from the order it is given (siteFor(o)), so every entry point is covered without any caller passing a site:Promise,PromiseGroups(ship-complete and per-line partial shipment), andFeasibleBy. The fieldPromisePolicy.SiteIdis renamedDefaultSiteIdand is ONLY the fallback;cmd/orderstill wires it fromDEFAULT_SITE_ID. -
Every promise path inherits it. All of them go through those three methods with the persisted order, whose site is immutable (ADR 0044 §4): intake and retry (
allocationDeps.setPromiseDate, forReceiveOrder,RetryAllocationandReleaseHeldOrder), the deadline-constrained hold (ADR 0020,FeasibleBy), and the re-promise consumer (RepromiseOrder.freshPromiseGroups, triggered by fulfillment-execution'sTaskCPTMissedsweep andPackageManifested) whoseOrderRepromisedtherefore carries old/new CPT ids of the order's own site. -
Every site-keyed read on the promise path, decided explicitly:
Read Keyed by site today? Decision CPT schedule — ScheduleSource.NextCutoffs(siteId, …),kafkacptschedulecache (schedules[site_id])yes Per order: PromiseSiteFor(o, DEFAULT_SITE_ID). An order at a site with no schedule yet falls back toLeadTimePolicy(or, forFeasibleBy, answers not feasible) — it never borrows another site's schedule.Planned capacity — OrderCapacityConstraints→PlannedCapacityRepo.ListByLocation(location, …)andorder.CapacityConstraints(…, site, …)yes (planning location)Per order, same rule, with PLANNED_CAPACITY_SITE_ID(itself defaulting toDEFAULT_SITE_ID) as the fallback.capacityConstraint.sitenames the site actually matched. Still advisory only (ADR 0031): the annotation never moves a promise.Path capacity — CapacitySource.Remaining(pathId, cptId, cutoffAt),kafkapathcapacitykeyed(PathId, CutoffAt)no Kept site-less. wes-work-planning's PathCapacityChangedcarries no site (path_id,cutoff_at,remaining_units,known): it is single-site today. No multi-site capacity data is invented; see Consequences.Capability — CapabilitySource.CycleTimeP95(pathId)and path eligibility,kafkacatalogno Kept site-less. process-path-management's path catalogue events carry no site; a path's cycle time is one fleet-wide value. Window eligibility ( EligiblePathIds) already comes from the per-site CPT schedule above.Demand projection — DemandProjectionPolicy.resolveyes Unchanged since ADR 0044 (per order, DEMAND_PROJECTION_SITE_IDfallback).LeadTimePolicyfallbackno Unchanged; it is not site-aware. -
Unchanged for every order without a site.
PromiseSiteForreturnsDEFAULT_SITE_ID(promise) /PLANNED_CAPACITY_SITE_ID(annotation), exactly the values used before this ADR, so behaviour, responses and events are byte-identical for every existing caller. -
No contract change. The frozen
OrderAllocated/OrderPartiallyAllocated/OrderRepromisedpayloads do not change by a byte and still do not carry the site (ADR 0044 §7). No new env var, no new chart value (INFRA VALUES REQUIRED: none). The OpenAPI change is descriptive only:fulfillmentSiteIdandCapacityConstraint.sitenow say which site the promise and annotation use.
Consequences
- A caller that names a site gets that building's cutoffs. The warehouse-day
simulator can put
fulfillmentSiteId: SIM1on its orders and PUT its compressed schedule onSIM1, leavingsite-1(the storefront's building) untouched; the storefront's orders, which carry no site, stay onDEFAULT_SITE_ID. - A caller can name a site whose CPT schedule this service has never seen. That
order is promised on the
LeadTimebasis (basis=LeadTimein the response), never on another site's windows — honest, and visible. - Known gap — path capacity is per path, not per site. Because
PathCapacityChangedhas no site, two sites whose CPT windows share the same(pathId, cutoffAt)read the same remaining-units figure. The exactCutoffAtmatch (ADR 0015) keeps this rare; fixing it needs a site on wes-work-planning's event first (a.v2, its decision), then a site key here. - Known gap — cycle time is per path, not per site. A building that is slower on the same path cannot say so until process-path-management's contract does.
- The site value object (
^[A-Z0-9]+$, ADR 0044 §3) cannot express a lower-case code such assite-1, so an order cannot explicitly name thesite-1building; it reaches it by naming no site. This is consistent with ADR 0044 (the default is the deployment's, not the caller's). - Verified by domain tests (an order at
SIM1promised onSIM1's schedule whilesite-1's differs; no site →DEFAULT_SITE_ID; re-promise stays on the order's site;FeasibleByjudged on the order's site only), use-case and HTTP tests, and a testcontainers integration test with a real Kafka CPT cache holding two sites and orders received and re-promised through real Postgres.