ADR 0021: Order demand and labour capacity read the event's own site
Status
Accepted (2026-11-15). Amends ADR 0004
§4 (the site assumption) and the site attribution of the labour consumer
recorded in ADR 0001's Addendum.
Additive: no topic, no CloudEvents type, no request or response shape, no
migration and no environment variable changes. DEMAND_SITE_ID stays required.
Context
ADR 0004 §4 attributed every consumed order to ONE configured site
(DEMAND_SITE_ID) because order-management's allocation events carried no
fulfillment site, and it stated the exit: "If the events later carry a usable
site, the consumer should read it and DEMAND_SITE_ID becomes a fallback."
That day has come. order-management's ADR 0050 (2026-11-06) added an optional
top-level site_id (string, omitempty) to OrderAllocated and
OrderPartiallyAllocated on warehouse.order-management.events: the order's
caller-assigned fulfillment site (its ADR 0044). An order without a site still
publishes exactly the pre-0050 bytes, the dataschema stays :v1, and
OrderRepromised carries no site. The pinned copy of that spec in
internal/adapters/inbound/kafka/testdata/ already carries the
orderAllocatedWithSite and orderPartiallyAllocatedWithSite examples, but
the consumer kept attributing them to DEMAND_SITE_ID, so the demand of every
sited order was counted at the wrong site.
Separately, workforce-management's ShiftPlanCommitted now names its site in
site_code (canonical, optional because it was added after v1 shipped) and
keeps building_id as a DEPRECATED twin with the same value. The labour
consumer read only building_id.
Two attributions are NOT affected and stay on DEMAND_SITE_ID:
fulfillment-execution's TaskCompleted still carries no site (ADR 0017
decision 3), and orders without a site still need one.
Decision
- Order demand reads
site_id.OrderDemandConsumerdecodes the optionalsite_idofOrderAllocated/OrderPartiallyAllocated. When it is present and not blank, the order'slocationis that value with surrounding space trimmed; it is otherwise used exactly as given (no case folding, no pattern check: order-management owns the value). When it is absent or blank, the order is attributed toDEMAND_SITE_ID, as before. - The site moves with the order. The read model keeps one row per order id
and last writer wins on the CloudEvents
time(ADR 0004 §3). A newer allocation of the same order at another site therefore moves the order to that site; an older one changes nothing. - Labour reads
site_codefirst.LaborCapacityConsumerusessite_codeas the constraint'slocationand falls back tobuilding_idonly whensite_codeis absent or blank. A line with neither (or without apath_id) is skipped with a warning, as a line withoutbuilding_idwas. DEMAND_SITE_IDstays required. It is the fallback for unsited orders and the only attribution for task completions. Its meaning in the configuration docs becomes "the fallback site".- No replay is forced. Rows already written keep their location. The
history is re-attributed only by replaying the topic under a new consumer
group, exactly as ADR 0004 §4 already describes for a changed
DEMAND_SITE_ID.
Consequences
GET /demand?location=<site>and plans that defaultassigned_demandfrom orders now see the orders of<site>as order-management sited them. A plan forDEMAND_SITE_IDno longer counts orders that order-management placed at another site, so its demand can drop.- The hot spot "order events carry no site" is closed for orders. It remains open for task completions (ADR 0017) and for orders that carry no site. Cancellations are still not netted (ADR 0004 §3).
- No new CloudEvents type, extension attribute or topic, so no CloudEvents ADR
catalogue change. The consumer contract test asserts each golden example lands
at its own
site_id, or at the configured site when it carries none.