warehouse-systems fleet · executive briefing

returns-processing

Decides what happens to each returned item, from restock to scrap
nine capabilitys7 events out · 4 in12 recorded decisions

This project is a domain-driven design study. It is not associated with, endorsed by or affiliated with any company, and it uses no company's code, data, logos or trademarks. All names, figures and examples are illustrative or synthetic. · November 2026

the short version · read this if nothing else

Returns Processing grades every returned line and routes it by policy, so recovered value follows a rule

1

Returns are only authorized against lines that were really allocated and shipped.

2

Each line gets one grade and an immutable decision; overrides add, never erase.

3

Restocked goods go to inventory-storage as staged lines, so the stock ledger stays theirs.

The ask

Add relay, consumer and poller metrics, and carry trace context through the outbox to follow a return.

why it exists

Returns hide value, and every line deserves a clear decision

returns-processing is the WMS-tier Supporting bounded context for goods coming back. It authorizes a return against an order line that was both allocated and shipped, receives the arriving parcel, records one inspection grade per line, and decides the disposition — RESTOCK, REFURBISH, LIQUIDATE, DISPOSE or RTV…

Today

It authorizes returns against shipped lines, receives parcels, grades each line once and decides disposition from a versioned policy.

The catch

Telemetry is one request histogram and one counter, so a stuck outbox or lagging copy shows only in logs and SQL.

what it does

Authorize, receive, grade, decide: one path for every return

Return authorization

Approves returns only for shipped lines, inside the window and caps.

Parcel receiving

Logs arrivals and flags unexpected parcels for exception handling.

One-time inspection

Each line gets exactly one grade, A through scrap, with a reason code.

Policy-driven disposition

Decides restock, refurbish, liquidate, dispose or return-to-vendor.

Reasoned overrides

Operators can override with a reason; the original decision stays.

Versioned policy

Policy changes are new versions, so every decision is traceable.

who it talks to

Three contexts feed it, two build on what it publishes

LISTENS TO · 4 EVENT TYPESIS HEARD BY · 2 CONTEXTSorder-management2fulfillment-execution1product-master1exception-management1inventory-storage1returnsprocessingbadge = event types on that edge · derived from the CloudEvents types each repo declares
the shared language

Grade, policy and disposition are the words that drive recovery

THE LANGUAGEOF THE DOMAINReturnAuthorization / RMAReturn windowReturnReceiptGradeDispositionOutcomeDispositionPolicyGuardrails
REST14 operations over 13 paths on :8080: POST|GET /returns…
MCPMCP server (cmd/mcp, :8090, Streamable HTTP): 3 read-only…
A2ARead-only A2A agent (cmd/a2a, :8093, JSON-RPC…
how it is built

Five binaries share one hexagonal core and a transactional outbox

DRIVERS · INBOUNDOUTBOUND · ADAPTERSREST API :808014 operations over 13 pathsMCP tools :8090MCP server (cmd/mcp, :8090…Kafka consumer · 4 eventsproduct.ProductClassifiedorder.OrderAllocatedDOMAIN COREReturnAuthorization / RMAReturn windowReturnReceiptGradePostgreSQLPostgreSQL onlyKafka producer · 7 eventsReturnAuthorizedReturnAuthorizationRejectedTransactional outboxrelay · DLQ on x-dlq-*commands inevents inevents outstorage / infra
event traffic · CloudEvents 1.0 on Kafka

Seven return facts tell stock and exception teams what to do

CONSUMED · BY SOURCE · 4PUBLISHED · BY ENTITY · 7order-management 2fulfillment-execution 1product-master 13 returnreceipt2 disposition2 returnauthorizationProductClassifiedOrderAllocatedOrderPartiallyAllocatedPackageManifestedReturnAuthorizedReturnAuthorizationRejectedReturnReceiptOpenedReturnLineInspectedUnexpectedReturnReceivedDispositionDecidedReturnLineStaged
how we know it is healthy

Traces and a decision counter exist, but queues and the poller are dark

Fleet observability standard (ADR 0011): every one of the five binaries pushes OTLP/gRPC traces and metrics every 15 s (lazy, non-blocking…

What we watch

  • Aggregated invalid-configuration error at boot then exit 1; readiness flips for postgres/kafka behind 503
  • Outbox relay poison-row dead-lettering with WARN logs and attempt-cap exclusion (re-arm documented)
  • Consumer death is a process death: the pod restarts rather than serving on frozen local copies

What stops a bad change

  • make check / check-fast / check-all; lefthook runs make check on commit and push
  • make coverage gates at 90% over internal/domain and internal/application
  • make mutation (gremlins, 95/95) per domain package; mutation-full scheduled
by the numbers

Twelve recorded decisions and 15 BDD features back the return rules

12
Architecture decisions
#31 of 45 in the fleet
3
DB migrations
#26 of 45 in the fleet
15
BDD feature files
#19 of 45 in the fleet
7
Events published
#17 of 45 in the fleet

Ranked against all 45 briefed repositories (dot = one repository, highest on the left).

One-command workflows (make)

api-lintarch-testbddbuildcheckcheck-allcheck-fastcoveragefmtfmt-checkguide-lintharness-testhelpintegration
what comes next

Next, we join traces across Kafka and prove the restock handoff

NOW1Carry trace contextthrough the outboxrelayPropagate W3C trace contextthrough the outbox relay tojoin REST and consumer paths:the outbox has no headerscolumn today(observability.md), so amigration is neededNEXT2Prove the restockhandoff withinventory-storage endExercise the staged-receiptseam with inventory-storageend-to-end once both run in acluster, including the RF stowpathLATER3Prove thereturn-advices pollerand refresh the docsProve the networkreturn-advices poller (ADR0012) against the live VendorAPI and refreshREADME/observability docs,which do not mention it (notevidenced in README.md,observability.md)LATER4Raise mutation gatefrom 95/95 to 99/99;fix README statusRaise the mutation gate(.gremlins.yaml 95% efficacy /95% mutant-coverage) to thefleet 99/99 standard; READMEStatus still says the firstrelease is pending althoughtags v0.1.0-v0.1.2 exist
what could go wrong · and what we do about it

Our biggest risk is a wrong policy rule quietly costing value

A wrong policy rule silently misroutes stock

Policy quality drives value recovery: a wrong grade/class rule silently routes stock to refurbish/liquidate/dispose…

→

Reasoned overrides supersede bad calls, and guardrails allow RESTOCK only for grade A or B.

Lagging local copies can reject fresh shipments

Local copies (allocated lines, manifested units, classes) can lag: authorization uses the copy…

→

No mitigation on the roadmap yet: this one needs an owner.

Unexpected returns rely on exception-management

Unexpected-return and override flows depend on exception-management and operator discipline…

→

No mitigation on the roadmap yet: this one needs an owner.

Relay, consumers and poller have no metrics

Telemetry is one request histogram and one authorization counter: the relay, the three consumers and the poller have no metric…

→

Add metrics for the relay, the consumers and the poller; today only logs and SQL show trouble.

the decision we need

Add relay, consumer and poller metrics, and carry trace context through the outbox to follow a return.

WHAT ISIt authorizes returns againstshipped lines, receives parcels,grades each line once and decidesdisposition from a versioned policy.THE CATCHTelemetry is one request histogramand one counter, so a stuck outboxor lagging copy shows only in logsand SQL.WHAT COULD BELeaders see the funnel and itsqueues live, traces join every path,and the restock handoff is proven ina cluster.
Why it matters

Returns Processing grades every returned line and routes it by policy, so recovered value follows a rule

appendix · for the engineers in the room

The fine print: how it is put together

StyleHexagonal (ports and adapters), one aggregate cluster per domain package; Open Host Service with Published Language; event-driven with transactional outbox
LayoutFive binaries: cmd/api (REST :8080 + three Kafka consumers + outbox relay + the opt-in network return-advices poller), cmd/mcp (Streamable HTTP :8090), cmd/a2a (JSON-RPC :8093, Agent Card)…
StoragePostgreSQL only (pgx; unit of work; 3 embedded golang-migrate migrations (schema, idempotency keys, return_advices) plus 1 analytics migration…
Testingmake check gates (fmt/vet/lint/test -race); 90% coverage gate over domain and application with the number in the CI summary…
REST14 operations over 13 paths on :8080: POST|GET /returns, GET /returns/{rmaId}, POST /returns/{rmaId}/receipts…
Go 1.27.4chipgx v5 + golang-migratekafka-go + CloudEvents SDK v2…MCP go-sdk v1.8.0OpenTelemetry Go SDK v1.47.0godog + testcontainersAnalytics read sideReact/Vite web remoteHelm chart