Use Cases
Derived from network/model/model.yaml. This context's service is built; the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses.
One application service per command in
contexts[vendor-connectivity].aggregates[*].commands, under
internal/application/usecases. The step-by-step runtime view is on
Sequence Diagrams.
Reads are not use cases. PollPurchaseOrders, GetPurchaseOrder,
GetTransaction and GetNode read repositories or read models directly;
GetScorecard relays node-performance's GET /scorecards/{nodeId}.
Conventions for every use case
- Errors are RFC 9457
application/problem+json. Mapping: validation422, conflict or state409, not found404, version conflict409. Thetypeis the slug shown: the shared slugs arenot-found,illegal-transition,concurrent-updateandvalidation-failed; the rest is one slug perErr...name (kebab-case, noErr). The earlier placeholdersvalidation,staleandpurchase-order-stateare not used (service ADR 0002;internal/adapters/inbound/http/errors.go). - Rate limit. Every
/vendor/...route may answer429rate-limitedwithRetry-Afterbefore the use case runs (RATE_LIMIT_RPS). - Idempotency-Key. Every
POST/PUTcarries one. A repeat with the same key and vendor returns the first response (for an asynchronous write, the sametransactionId). - Synchronous refusal vs failed transaction. Rules this context can
check at receipt are refused synchronously (no transaction is created).
Refusals by a neighbour during processing end the transaction in
FAILURE, with the neighbour'sErr...inSubmissionError.code. This split is proposed; the model does not state it. - One transaction per use case: the aggregate change, its outbox rows and (for consumers) the inbox row commit together.
| Model error | HTTP | Problem type |
|---|---|---|
ErrAckWindowOutOfRange | 422 | ack-window-out-of-range |
ErrNodeNotOwnedByVendor | 404 | node-not-owned-by-vendor (404, so a vendor cannot probe another vendor's nodes) |
ErrPartialAcknowledgement | 422 | partial-acknowledgement |
ErrAlreadyAcknowledged | 409 | already-acknowledged |
ErrAckWindowClosed | 409 | ack-window-closed |
ErrLabelBeforeAcceptance | 409 | label-before-acceptance |
ErrConfirmWithoutLabel | 409 | confirm-without-label |
ErrVendorSuspended | 409 | vendor-suspended (every vendor write while the vendor is SUSPENDED) |
ErrCancelAfterAcknowledgement | no HTTP (Kafka consumer) | would be 409 cancel-after-acknowledgement |
ErrSubmissionAlreadyProcessed | no HTTP (internal) | would be 409 submission-already-processed |
ErrSubmissionNotDue | no HTTP (internal) | would be 409 submission-not-due |
ErrNotFound: purchase order, vendor, node or transaction unknown | 404 | not-found |
ErrValidation: request body malformed | 422 | validation-failed |
ErrIllegalTransition: a command from a state that has no dedicated Err... | 409 | illegal-transition |
ErrConcurrentUpdate: optimistic-concurrency version conflict | 409 | concurrent-update (retried once inside the use case before it is returned) |
ErrUpstreamUnavailable: a neighbouring context did not answer | 503 | upstream-unavailable |
ErrUpstreamRefused: a neighbouring context answered with a refusal this context does not translate | 502 | upstream-refused |
OnboardVendor
- Actor / trigger: network partner manager.
- Inbound adapter: REST
POST /vendors(internal/adapters/inbound/http). - Preconditions: none on other aggregates.
- Main flow:
- Validate
vendorId,name,ackWindowMinutes. vendor.Onboard(vendorId, name, ackWindow): checks 1h to 24h.- Save the
VendorAccount(ACTIVE) and writeVendorOnboardedto the outbox in one transaction. - Return
201with the account.
- Validate
| Error | HTTP | Problem type |
|---|---|---|
ErrAckWindowOutOfRange | 422 | ack-window-out-of-range |
- Events:
VendorOnboarded. - Idempotency:
Idempotency-Key; a second onboarding of an existingvendorIdwith a new key returns the existing account unchanged,200(service ADR 0002 A8; the model has no duplicate-vendor error).
SuspendVendor
- Actor / trigger: network partner manager.
- Inbound adapter: REST
POST /vendors/{vendorId}/suspensions(optional bodyreason, 1 to 200 characters). - Preconditions: the vendor exists.
- Main flow:
- Load the
VendorAccount. Suspend():ACTIVEtoSUSPENDED.- Save with a version check and write
VendorSuspendedto the outbox in one transaction.
- Load the
- Effect while
SUSPENDED(service ADR 0002 A9): every vendor write is refused with 409vendor-suspended(ErrVendorSuspended): acknowledgement, inventory feed, node registration, node profile, label request, shipment confirmation and inbound receipt. Reads, polling, the issuing of new purchase orders, the expiry sweep and the processing of submissions already received continue.
| Error | HTTP | Problem type |
|---|---|---|
| vendor unknown | 404 | not-found |
| version conflict | 409 | concurrent-update |
- Events:
VendorSuspended(vendorId,suspendedAt, optionalreason) onretailnetwork.vendor-connectivity.events; no context consumes it yet (service ADR 0002 A14, ADR 0004). - Idempotency: suspending a
SUSPENDEDvendor is a no-op:200with the account unchanged and no event (service ADR 0002 A8).
ReinstateVendor
- Actor / trigger: network partner manager.
- Inbound adapter: REST
POST /vendors/{vendorId}/reinstatements. - Preconditions: the vendor exists.
- Main flow:
- Load the
VendorAccount. Reinstate():SUSPENDEDtoACTIVE.- Save with a version check and write
VendorReinstatedto the outbox in one transaction.
- Load the
| Error | HTTP | Problem type |
|---|---|---|
| vendor unknown | 404 | not-found |
| version conflict | 409 | concurrent-update |
- Events:
VendorReinstated(vendorId,reinstatedAt) onretailnetwork.vendor-connectivity.events; no context consumes it yet. - Idempotency: reinstating an
ACTIVEvendor is a no-op:200with the account unchanged and no event (service ADR 0002 A8).
IssuePurchaseOrder
- Actor / trigger: policy
IssueOnRelease, oncom.retailnetwork.commerce.order-sourcing.assignment.FulfillmentReleasedToNode. - Inbound adapter: Kafka consumer on
retailnetwork.order-sourcing.events(internal/adapters/inbound/kafka). - Preconditions:
nodeIdis aVENDORnode inVendorNodeView; its vendor has aVendorAccount. - Main flow:
- Claim the CloudEvents
idinprocessed_events; a duplicate stops here. - Look up the node in
VendorNodeView. Not a vendor node: record the inbox row and stop. - Derive
poNumberfromassignmentId + releaseNo. If it exists, stop. - Load the vendor's ack window and the node's
handlingTimeMinutesfromVendorNodeView, whichNodeOperationalProfileDeclaredfeeds (a lowerprofileRevisionnever overwrites a higher one). A node with no declared profile has handling time 0 (service ADR 0002 A3). po.Issue(...)withrequiredShipBy,lines(listingId,quantity, numberedlineNo) andackBy = min(issuedAt + ackWindow, requiredShipBy - handlingTime).- Save (
ISSUED), writePurchaseOrderIssuedto the outbox, commit with the inbox row.
- Claim the CloudEvents
| Error | HTTP | Problem type |
|---|---|---|
node not in VendorNodeView yet | no HTTP | not acknowledged on Kafka; retried, so the release is not lost to an event race |
- Events:
PurchaseOrderIssued. - Idempotency: the inbox on the event
id, andpoNumberonassignmentId + releaseNo. - Handling time: consumed from
NodeOperationalProfileDeclared(service ADR 0003); there is no gap.
SubmitAcknowledgement
- Actor / trigger: vendor.
- Inbound adapter: Vendor API
POST /vendor/acknowledgements. - Preconditions: the PO exists, belongs to a node of
vendorId, isISSUED, and now is not afterackBy. - Main flow:
- Load the PO by
poNumber; check ownership throughVendorNodeView. po.SubmitAcknowledgement(decision, reasonCode, lines, now): every line once at its ordered quantity, one decision, beforeackBy.- In one transaction: save the PO (
ACK_PROCESSING, decision recorded) andReceiveSubmissionaSubmissionof kindACKNOWLEDGEMENT(PROCESSING,notBefore = receivedAt + TX_PROCESSING_DELAY). - Return
202 {transactionId}.
- Load the PO by
| Error | HTTP | Problem type |
|---|---|---|
ErrPartialAcknowledgement | 422 | partial-acknowledgement |
ErrAlreadyAcknowledged | 409 | already-acknowledged |
ErrAckWindowClosed | 409 | ack-window-closed |
ErrNodeNotOwnedByVendor | 404 | node-not-owned-by-vendor |
ErrVendorSuspended | 409 | vendor-suspended |
| PO unknown | 404 | not-found |
a CANCELLED PO (ErrIllegalTransition) | 409 | illegal-transition |
REJECT without reasonCode | 422 | validation-failed |
| version conflict | 409 | concurrent-update |
- Events: none at receipt.
PurchaseOrderAcceptedorPurchaseOrderRejectedandSubmissionProcessedfollow fromProcessSubmission. - Idempotency:
Idempotency-Keyreturns the sametransactionId. A second acknowledgement with a new key isErrAlreadyAcknowledgeduntil a failed transaction returns the PO toISSUED. - Other states (service ADR 0002 A7): an acknowledgement of a
CANCELLEDPO isErrIllegalTransition;EXPIREDis pastackByand getsErrAckWindowClosed.
RequestLabel
- Actor / trigger: vendor.
- Inbound adapter: Vendor API
POST /vendor/shipping-labels. - Preconditions: the PO is
ACCEPTEDand belongs to the vendor. - Main flow:
- Load the PO; check ownership.
po.CanLabel():ACCEPTEDonly.- For each requested
packageNo, call shipping-and-trackingPOST /labels(IssueLabel) withpoNumber,assignmentId,packageNo. The address is resolved there and never returned. po.AddLabels(labels):labelRef,trackingNumber,carrier.- Save; return
200with the labels.
| Error | HTTP | Problem type |
|---|---|---|
ErrLabelBeforeAcceptance | 409 | label-before-acceptance |
ErrNodeNotOwnedByVendor | 404 | node-not-owned-by-vendor |
ErrVendorSuspended | 409 | vendor-suspended |
| PO unknown | 404 | not-found |
a REJECTED, EXPIRED or CANCELLED PO (ErrIllegalTransition) | 409 | illegal-transition |
shipping-and-tracking did not answer (ErrUpstreamUnavailable) | 503 | upstream-unavailable |
shipping-and-tracking refused with an answer this context does not translate (ErrUpstreamRefused) | 502 | upstream-refused |
- Events: none here; shipping-and-tracking publishes
LabelIssued. - Idempotency: shipping-and-tracking issues one label per
(poNumber, packageNo)(ErrLabelAlreadyIssuedthere); this use case returns the stored label for a package it already holds. - Partial failure: labels already issued stay stored when a later package fails; the answer is then 503 or 502 and a retry returns the stored labels and issues only the missing ones (service ADR 0002 A19).
- Gap: synchronous, unlike every other vendor write.
SubmitShipmentConfirmation
- Actor / trigger: vendor.
- Inbound adapter: Vendor API
POST /vendor/shipment-confirmations. - Preconditions: the PO is
ACCEPTED, has labels, and everytrackingNumberin the request is one of its labels. - Main flow:
- Load the PO; check ownership.
po.SubmitShipmentConfirmation(trackingNumbers, shippedAt).- In one transaction: save the PO (
SHIPMENT_PROCESSING) andReceiveSubmissionof kindSHIPMENT_CONFIRMATION. - Return
202 {transactionId}.
| Error | HTTP | Problem type |
|---|---|---|
ErrConfirmWithoutLabel | 409 | confirm-without-label |
ErrNodeNotOwnedByVendor | 404 | node-not-owned-by-vendor |
| PO unknown | 404 | not-found |
ErrVendorSuspended | 409 | vendor-suspended |
PO SHIPMENT_PROCESSING, SHIPPED, REJECTED, EXPIRED or CANCELLED (ErrIllegalTransition) | 409 | illegal-transition |
| version conflict | 409 | concurrent-update |
- Events: none at receipt;
VendorShipmentConfirmedandSubmissionProcessedfollow fromProcessSubmission. - Idempotency:
Idempotency-Key. A confirmation while one is processing is refused by state. - Other states (service ADR 0002 A7): a confirmation against an
ISSUEDorACK_PROCESSINGPO isErrConfirmWithoutLabel(no label can exist yet); againstSHIPMENT_PROCESSING,SHIPPED,REJECTED,EXPIREDorCANCELLEDit isErrIllegalTransition.
ExpireUnacknowledgedOrders
- Actor / trigger: policy
ExpireUnacknowledged(sweep timer). - Inbound adapter: internal ticker (
cmd), no route. - Preconditions: the PO is
ISSUEDand now is afterackBy. - Main flow:
- List
ISSUEDPOs withackByin the past. - For each:
po.Expire(now), save with a version check, writePurchaseOrderExpiredto the outbox, commit.
- List
| Error | HTTP | Problem type |
|---|---|---|
| version conflict (the vendor acknowledged meanwhile) | no HTTP | skipped; the next pass re-reads |
- Events:
PurchaseOrderExpired. - Idempotency: only
ISSUEDPOs are expired; anEXPIREDone is not listed again. A PO inACK_PROCESSINGis never expired; if its transaction fails afterackBy, it returns toISSUEDand the next pass expires it.
CancelPurchaseOrder
- Actor / trigger: policy
CancelOnSourcingCancel, oncom.retailnetwork.commerce.order-sourcing.assignment.FulfillmentCancelled. - Inbound adapter: Kafka consumer on
retailnetwork.order-sourcing.events. - Preconditions: a PO exists for that
assignmentIdand isISSUED. Any other state is refused:ErrCancelAfterAcknowledgementforACK_PROCESSING,ACCEPTED,REJECTED,SHIPMENT_PROCESSINGandSHIPPED, andErrIllegalTransitionforEXPIREDandCANCELLED(PurchaseOrder.Cancel). Both are logged at INFO and acknowledged, so the observable result is the same. - Main flow:
- Claim the event
idin the inbox. - Find the PO of the assignment's open release (the event carries
assignmentIdbut noreleaseNo; order-sourcing allows one pending release at a time). po.Cancel(reason):ISSUEDonly.- Save, write
PurchaseOrderCancelled, commit with the inbox row.
- Claim the event
| Error | HTTP | Problem type |
|---|---|---|
ErrCancelAfterAcknowledgement (the order is past acknowledgement and not EXPIRED or CANCELLED) | no HTTP | logged at INFO; the inbox row is written so the event is not retried |
ErrIllegalTransition (the order is EXPIRED or CANCELLED) | no HTTP | logged at INFO; the inbox row is written, nothing is published |
| no PO for the assignment | no HTTP | inbox row written, nothing else |
- Events:
PurchaseOrderCancelled. - Idempotency: the inbox; a
CANCELLEDPO is left as is (it answersErrIllegalTransition, logged and acknowledged). - Gap: nothing tells the vendor or order-sourcing when the cancel is refused after acknowledgement.
CancelOnReleaseWithdrawn
- Actor / trigger: policy
CancelOnReleaseWithdrawn, oncom.retailnetwork.commerce.order-sourcing.assignment.FulfillmentReleaseWithdrawn(assignmentId,releaseNo,orderId,groupNo,reason,withdrawnAt). - Inbound adapter: the Kafka consumer already subscribed to
retailnetwork.order-sourcing.events. - Preconditions: a PO exists for (
assignmentId,releaseNo) and isISSUED. - Main flow: claim the event
idin the inbox; find the order by (assignmentId,releaseNo); not found is a no-op;po.Cancel('release withdrawn: ' + reason)(sanitised, at most 200 characters); save and writePurchaseOrderCancelledin the same transaction as the inbox row. - Errors:
ErrCancelAfterAcknowledgement(the order is past acknowledgement:ACK_PROCESSING,ACCEPTED,REJECTED,SHIPMENT_PROCESSINGorSHIPPED) andErrIllegalTransition(EXPIREDor alreadyCANCELLED) are logged at INFO and acknowledged, not retried. - Events:
PurchaseOrderCancelled. - Idempotency: the inbox. The lookup is by release number, so it never touches the order of a later release. The reason is carried as opaque text; this context does not branch on it.
- Residual (owned by
order-sourcing): between the dissolve and this cancel the vendor may acknowledge; the order is thenACCEPTED, it is left as it is andorder-sourcingignores the stale acceptance.
ReceiveSubmission
- Actor / trigger: vendor, for the three relay writes below. The acknowledgement and shipment-confirmation use cases above also call it inside their own transaction.
- Inbound adapter: Vendor API
POST /vendor/nodes(RegisterVendorNode, kindNODE_REGISTRATION),PUT /vendor/nodes/{nodeId}/profile(DeclareNodeProfile, kindNODE_PROFILE),POST /vendor/inventory(SubmitInventory, kindINVENTORY). - Preconditions: the body is well-formed; for profile and inventory,
the node belongs to
vendorIdinVendorNodeView. - Main flow:
- Validate the body and, where a node is named, ownership.
submission.Receive(vendorId, kind, payload, now, delay): statusPROCESSING,notBefore = receivedAt + TX_PROCESSING_DELAY.- Save; return
202 {transactionId}.
| Error | HTTP | Problem type |
|---|---|---|
ErrNodeNotOwnedByVendor | 404 | node-not-owned-by-vendor |
ErrVendorSuspended | 409 | vendor-suspended |
| node unknown | 404 | not-found |
| body malformed | 422 | validation-failed |
- Events: none at receipt.
- Idempotency:
Idempotency-Keyper vendor, stored on the submission.
ProcessSubmission
- Actor / trigger: the submission processor (internal ticker).
- Inbound adapter: none;
cmdworker. - Preconditions: the submission is
PROCESSINGand now is at or afternotBefore. - Main flow:
- Pick due
PROCESSINGsubmissions. - Apply
TX_FAILURE_RATE: a drawn failure ends the submission inFAILUREwith a simulatedSubmissionError. - Otherwise by kind:
NODE_REGISTRATION: node-topologyPOST /nodes(RegisterNode).NODE_PROFILE: node-topologyPUT /nodes/{nodeId}/operational-profile.INVENTORY: offer-availabilityPOST /inventory-feeds.ACKNOWLEDGEMENT,SHIPMENT_CONFIRMATION: no call. A4xxfrom a neighbour isFAILUREwith itsErr...ascode; a5xxor timeout leaves the submissionPROCESSINGfor the next pass.
submission.Complete(status, errors).- For
ACKNOWLEDGEMENTandSHIPMENT_CONFIRMATION, apply the outcome to the PO:ACK_PROCESSINGtoACCEPTED,REJECTEDor back toISSUED;SHIPMENT_PROCESSINGtoSHIPPEDor back toACCEPTED. - In one transaction: save the submission and the PO, write
SubmissionProcessedand, where a PO changed, its event.
- Pick due
| Error | HTTP | Problem type |
|---|---|---|
ErrSubmissionNotDue | no HTTP | skipped until notBefore |
ErrSubmissionAlreadyProcessed | no HTTP | skipped (a second processor got there first) |
| version conflict on the PO | no HTTP | the whole transaction rolls back and is retried |
- Events:
SubmissionProcessed; and one ofPurchaseOrderAccepted,PurchaseOrderRejected,VendorShipmentConfirmedon success of the PO kinds. - Idempotency:
ErrSubmissionAlreadyProcessed; relayed calls are idempotent downstream (profileRevision,feedId,vendorNodeCode). - Note: step 6 changes two aggregates in one local transaction so that
a vendor reading
SUCCESSalways sees the PO in its new state. This is a proposed exception to "one aggregate per transaction", listed as an open question.
SubmitInboundReceipt
Built, ADR 0009 as realized by
vendor-connectivityADR 0005 (inbound shipments, inbound receipts and catalogue packaging). This section is the delta the seller-inbound design added to this page; where the service decided differently, the text below says so.
- Actor / trigger: a vendor (for the fleet,
network-fulfillment). RESTPOST /vendor/inbound-receiptswith anIdempotency-Key. - Preconditions: the shipment is in
InboundShipmentViewand itsnodeIdbelongs to the vendor. - Flow: validate the body (carton statuses, GTIN and SSCC shapes, quantities as eaches), create a
Submissionof kindINBOUND_RECEIPTinPROCESSING, return202with thetransactionId.InboundReceiptSubmittedis appended to the outbox in the same unit of work, so a202always has its event;ProcessSubmissionlater reportsSubmissionProcessed(service ADR 0005). - Errors:
ErrNodeNotOwnedByVendor(404), a suspended vendor (409vendor-suspended), an unknown vendor, shipment or node (404not-found, so a vendor cannot probe another vendor's shipments; the design named itErrUnknownInboundShipment), body malformed (422validation-failed). - Reads:
GET /vendor/inbound-shipments?vendorId=&nodeId=&createdAfter=&nextCursor=&limit=andGET /vendor/inbound-shipments/{shipmentId}readInboundShipmentViewdirectly. They return the shipment as a tree (shipment, optional pallet, carton, item) withsscc,gtin,qtyEaches,lot,expiryandsellerId(the seller of record, which the vendor keeps as itsownerRef).
SubmitReturnOutcome
Built, ADR 0012 as realized by
vendor-connectivityADR 0014 (return advices and return outcomes).
- Actor / trigger: a vendor's returns-centre system. REST
POST /vendor/return-outcomeswith anIdempotency-Key. The fleet'snetwork-fulfillmenthas no client for it on itsdevelop. - Preconditions: the authorization is in
ReturnAdviceViewand stillAUTHORIZED;nodeIdis the advice's node and belongs to the vendor. - Flow: validate the body (
vendorId,authorizationId,nodeId,receivedAt, 1 to 50 lines ofcatalogItemId, optionalownerRef,qtyRestockable,qtyUnsellable), create aSubmissionof kindRETURN_OUTCOME, move the advice toOUTCOME_RECORDEDand appendVendorReturnOutcomeSubmittedto the outbox in the same unit of work, return202with thetransactionId. Lines the advice never authorized are reported, never refused;customer-returnsrecords them as unexpected. - Errors: a suspended vendor (409
vendor-suspended), an unknown vendor, authorization or node (404not-found),ErrNodeNotOwnedByVendor(404), an advice that is notAUTHORIZED(409illegal-transition), anodeIdthat is not the advice's node or a malformed body (422validation-failed). - Events:
VendorReturnOutcomeSubmitted(subject and keyauthorizationId), consumed bycustomer-returns. - Reads:
GET /vendor/return-advices?vendorId=&readyAfter=&nodeId=&cursor=&limit=(PollReturnAdvices) andGET /vendor/return-advices/{authorizationId}(GetReturnAdvice) readReturnAdviceViewdirectly. The poll answers theAUTHORIZEDadvices of the vendor's nodes, oldest first; the single read also answers a closed advice (CANCELLEDorOUTCOME_RECORDED).