Skip to main content

Sequence Diagrams

One UML sequence per command use case on Use Cases. Shared conventions:

  • A repository saves with WHERE version = :expected; zero rows updated is a version conflict (ErrConcurrentUpdate, 409 concurrent-update), and Service.atomically re-runs the unit once.
  • Outbox rows are written in the same database transaction as the aggregate (UoW); a separate relay reads unpublished rows and produces them to Kafka retailnetwork.vendor-connectivity.events, then marks them published. The relay is drawn once per diagram as Relay + Kafka.
  • Consumers claim the CloudEvents id in processed_events in the same transaction as their effect.
  • Every /vendor/... request passes the rate limiter first (429 with Retry-After); it is drawn only in diagram 4.
  • Every write route sits behind the transactional Idempotency-Key middleware, which opens the Postgres transaction the use case then joins; a replay of the same key and body returns the stored answer without running the use case, and a 5xx rolls everything back.

Event names are short; the full types are on Domain Events.

1. OnboardVendor​

Source: internal/application/usecases/vendors.go (OnboardVendor) and internal/adapters/inbound/http/server.go.

Omitted: the Idempotency-Key replay (returns the stored answer); body validation (422 validation-failed).

2. SuspendVendor and ReinstateVendor​

Source: internal/application/usecases/vendors.go (SuspendVendor, ReinstateVendor) and handleVendorAction in internal/adapters/inbound/http/handlers.go.

Omitted: the outbox append and the relay, which work as in diagram 1 (VendorSuspended or VendorReinstated, key vendorId); a no-op raises no event. A suspended vendor's later writes answer 409 vendor-suspended.

3. IssuePurchaseOrder (policy IssueOnRelease)​

Source: internal/application/usecases/orders.go (IssueOnRelease, issue), service.go (consume) and internal/adapters/inbound/kafka/consumers.go.

Omitted: where handlingTime comes from (the node view, fed by NodeOperationalProfileDeclared); a vendor with no account or an invalid release is logged and dropped; PO_REDELIVERY_RATE, which acts on the poll, not here.

4. SubmitAcknowledgement​

Source: internal/application/usecases/orders.go (SubmitAcknowledgement), internal/adapters/inbound/http/ratelimit.go and idempotency.go.

Omitted: the relay, because nothing is published at receipt; PurchaseOrderAccepted or PurchaseOrderRejected follows in diagram 10. The version-conflict branch is retried once inside the use case before it is returned. A 2xx and a refusal that is final for the request (partial-acknowledgement, ack-window-closed) are stored by the middleware and replayed for the same key; any other refusal (concurrent-update, not-found, vendor-suspended, ...) is not stored and releases the key (ADR 0015).

5. RequestLabel​

Source: internal/application/usecases/orders.go (RequestLabel, issueLabels, storeLabels) and internal/adapters/outbound/httpclient/clients.go.

Omitted: outbox and relay, because this context publishes nothing here (shipping-and-tracking publishes LabelIssued). shipping-and-tracking unavailable answers 503 upstream-unavailable, a refusal 502 upstream-refused; labels issued before the failure are stored and returned on the next request.

6. SubmitShipmentConfirmation​

Source: internal/application/usecases/orders.go (SubmitShipmentConfirmation) and internal/domain/purchaseorder/commands_shipment.go.

Omitted: rate limiting and the 404 branch (as in diagram 4); VendorShipmentConfirmed follows in diagram 10.

7. ExpireUnacknowledged (the expiry sweeper)​

Source: internal/application/usecases/orders.go (ExpireUnacknowledged) and cmd/api/background.go (startBackground).

Omitted: a PO in ACK_PROCESSING is not listed; it is expired on a later pass only if its transaction fails and returns it to ISSUED after ackBy.

8. CancelOnSourcingCancel​

Source: internal/application/usecases/orders.go (CancelOnSourcingCancel) and internal/domain/purchaseorder/commands.go (Cancel).

Omitted: a version conflict rolls back the whole transaction, including the inbox row, so Kafka redelivers the event and the cancel is retried.

9. Receiving a node registration, profile or inventory write​

Source: internal/application/usecases/submissions.go (receiveOnly, RegisterVendorNode, DeclareNodeProfile, SubmitInventory).

Omitted: rate limiting and body validation (422 validation-failed); outbox and relay, because nothing is published at receipt. An inventory line whose listing belongs to another node is refused at receipt. Inbound receipts follow the same shape, with a shipment check and an InboundReceiptSubmitted event appended in the same unit.

10. ProcessSubmission​

Source: internal/application/usecases/submissions.go (ProcessDueSubmissions, process, execute, finish).

Omitted: the PO event is PurchaseOrderAccepted, PurchaseOrderRejected or VendorShipmentConfirmed on success, and none on failure. Changing two aggregates in one transaction is deliberate: finish saves the order, the submission and the outbox rows in one unit of work (see Use cases). Acknowledgements, shipment confirmations and inbound receipts succeed at once; a processed submission whose order has moved on is logged and the order left as is.