ADR 0009: inbound timeliness and accuracy, two informational scorecard metrics
Status
Accepted (2026-10-24). Design source: warehouse-docs network/model/model.yaml, context
node-performance (value object Metrics, policy InboundObservations) and the mastercase
contracts, section 10 (P3, P6).
Context
Phase 4 lets sellers ship cartons to a node. Two producers say what happened to a shipment:
seller-inbound's InboundShipmentShipped (when it left) and vendor-connectivity's
InboundReceiptSubmitted (what the node's dock reported, carton by carton, and when). The model
adds inboundTimelinessP95Minutes and inboundAccuracyRate to the scorecard Metrics and states
that they are "informational: not an input to Grading and not on NodeScorecardUpdated".
Decision
- Informational only. The grade (A to D),
MinObservations, the scorecardobservationscount, thePROVISIONAL/GRADEDstate,NodeScorecardUpdatedandNodeThresholdBreachedare unchanged. The model is explicit, so nothing is left to an assumption here: no inbound fact becomes a scorecardObservation, no scorecard is created or marked dirty by one, and no event is published for one. - Inputs.
com.retailnetwork.partner.vendor-connectivity.inboundreceipt.InboundReceiptSubmittedon the existing vendor-connectivity topic and group. Relied on:shipmentId,nodeId,receivedAt,cartons[].status. Everything else (transactionId,vendorId,items,complianceCodes, ...) is ignored.com.retailnetwork.partner.seller-inbound.inboundshipment.InboundShipmentShippedonretailnetwork.seller-inbound.eventsunder a NEW consumer group read from the mandatorySELLER_INBOUND_CONSUMER_GROUP(chart valueconfig.sellerInboundConsumerGroup). Relied on:shipmentId,nodeId,shippedAt. The producer was not merged when this was built: the consumer follows the written contract (section 10, P3) with a tolerant local copy inapis/asyncapi.yaml; re-check it against the producer's AsyncAPI when it lands.
- Local read models (migration
0003):inbound_shipments(shipment_id PK, node_id, shipped_at)andinbound_receipts(shipment_id PK, node_id, received_at, cartons_total, cartons_received). The first fact stored pershipmentIdwins (ON CONFLICT DO NOTHING), in both tables. - Join and parking. The read joins receipt and shipment by
shipmentIdonly. A receipt that arrives before itsInboundShipmentShippedis simply stored and not returned by the (inner) join; it counts from the moment the shipment arrives. It is never dropped and never counted twice: one receipt per shipment counts (a second report of the same shipment, under another CloudEvents id, is a duplicate outcome), and a redelivered event is stopped by the inbox (processed_events, keyed by the CloudEvents id) in the same transaction. The receipt is attributed to the node of the RECEIPT. - Timeliness. One sample per joined receipt:
receivedAt - shippedAttruncated to whole minutes. Negative durations are clamped to 0, not rejected: two producers' clocks can disagree by a few minutes, and the carton counts of the receipt are real facts that must not be lost. The metric is the nearest-rank p95 (ceil(0.95 * n)-th smallest, the rule of A9); one sample is its own p95. Lower is better. - Accuracy. Cartons whose status is exactly
RECEIVEDover all cartons reported, POOLED over the receipts of the window (not a mean of per-receipt rates, so a ten-carton receipt weighs ten times a one-carton receipt).MISSING,UNEXPECTED,DAMAGEDand any unknown status count as not received. A receipt with no cartons adds a timeliness sample and nothing to the accuracy. Higher is better. - Window. Same rule as A3: a receipt counts in a window at
nowwhen itsreceivedAtis afternow - window(a future instant counts). The 7d and 30d scorecards of a node each get their own value. - Derived at read time. The two metrics are computed when the scorecard is read
(
GET /scorecards/{nodeId}andGET /scorecards?grade=), from the joined read models and the service clock, not stored on thescorecardsrow. Hence they need no recompute, change no aggregate version and are always as fresh as the last consumed event, while the other metrics stay as ofcomputedAt. The list read fetches all nodes of the page in one query. - Wire.
Metricsgains the optionalinboundTimelinessP95Minutes(integer, minutes) andinboundAccuracyRate(number in [0,1]) inapis/openapi.yaml, OMITTED when the window has no joined receipt (timeliness) or no carton (accuracy): "no data" is not a best value here, unlike A5, because an absent measurement must not read as a perfect one. Additive, so existing consumers are unaffected.apis/asyncapi.yamlgains the two consumed messages and the seller-inbound channel;NodeScorecardUpdatedis unchanged.
Consequences
- Six consumers now run (was five); the shutdown budget in
cmd/apiawaits one more worker, and the chart refuses to render without the sixth group id. - A vendor-connectivity receipt for a shipment seller-inbound never announces stays stored and
invisible: bounded by the number of receipts, no expiry yet. An
inbound_*retention sweep is a follow-up if volume ever matters. - If the model later wants inbound to feed the grade, that is a new ADR: the facts would have to
become
Observations (counted towardsMinObservations) and a threshold table entry (A11).