ADR 0015: Return completions restock owner listings
Status
Accepted (2026-11-14). Extends ADR 0003 and ADR 0004 with the first consumed type of the customer-returns context, on a topic this service did not read yet. Builds the same shape of fact as ADR 0014: an event-fed quantity change of an owner listing.
Context
The customer-returns context (wave 4) closes a return at a node and publishes what physically came back. The orchestrator's contract, verbatim:
- OA (branch
feature/returns-restock, ADR 0015, migration 0005): consumesReturnCompleted(new consumer groupoffer-availability-customer-returnson the CR topic) exactly like the SI received-stock consumer (F28): per line, raise availability of the owner listing atnodeIdbyqtyRestockable; lines without a known listing are counted and skipped (WARN). Unsellable units never touch listings.
The consumed event (the design's event shape is the contract; the producing repo lands in parallel with goldens that match it):
- type
com.retailnetwork.commerce.customer-returns.returnauthorization.ReturnCompletedonretailnetwork.customer-returns.events, subject and Kafka keyauthorizationId, source/retailnetwork/customer-returns; data = {authorizationId, outcome: RECEIVED, nodeId, lines: [{catalogItemId, ownerRef, qtyRestockable, qtyUnsellable}], receivedAt};qtyRestockableis the count the node can sell again,qtyUnsellablethe count it cannot;ownerRefis the seller whose stock was returned (the id the fulfillment lock carried), empty meaning the operator's own stock.
Golden payload (the consumer decode test pins it):
{"authorizationId":"ret-1","outcome":"RECEIVED","nodeId":"n-1",
"lines":[{"catalogItemId":"item-1","ownerRef":"S-1","qtyRestockable":2,"qtyUnsellable":1}],
"receivedAt":"2026-11-14T12:00:00Z"}
Decision
- Consumed type.
ReturnCompletedis consumed fromretailnetwork.customer-returns.eventsunder the new mandatoryCUSTOMER_RETURNS_CONSUMER_GROUP(a boot error when unset, like the other groups; never a literal). Dispatch on the fulltype; every other type on the topic is acknowledged and counted. Fields read:authorizationId,nodeId,lines[].{catalogItemId, ownerRef, qtyRestockable, qtyUnsellable}andreceivedAt(the CloudEventstimewhen the payload carries no instant).outcomeis not read:ReturnCompletedis published for one outcome only. - Use case
ApplyReturnCompletion. ONE unit of work per event, the CloudEvents id recorded inprocessed_eventsfirst (a redelivery changes nothing). Then, in the order oflines:- a line with
qtyRestockable <= 0is skipped and counted (nothing_restockable): unsellable units never touch a listing, and a line that restocks nothing has nothing to do; - a line without a usable
catalogItemId(absent or not a valid id) is skipped and counted (item_absent), never an error; - the listing of
(catalogItemId, nodeId, ownerRef)is looked up; a line with no such listing is skipped and counted (listing_unknown) and logged at WARN — the return was real, only the listing is missing (the item is not offered from that node for that owner, or the listing was never created); - a found listing is restocked by
qtyRestockable(below). ItsListingAvailabilityChangedis appended to the outbox in the same transaction.
- a line with
Listing.Restock(qty, at, ref). A restock is a DELTA, not a snapshot: the available quantity becomesavailableQty + qty; a feed replaces the whole value, a return completion adds to it. The basis never changes (a listing that never had a feed staysUNKNOWN; the vendor's claim is still the only basis knower). The provenance pair(asOf, feedId)moves only forward: a restock newer than the current fact stamps the pair withreceivedAtand theauthorizationId; a restock older than the current fact leaves the feed's stamp and still adds its quantity. The state is not touched (A8): a SUPPRESSED listing is restocked too, so the quantity is right the day the cause clears.- Skips are counted, never errors, on the new counter
availability.customer_returns_events.ignored(attributestype,reason; the fleet naming, mirroringavailability.seller_events.ignored):type_not_consumed(one per event of another type),nothing_restockable,item_absent,listing_unknown(one per skipped line). The counts are recorded after the unit of work commits, so a retried attempt or a redelivered id never counts twice. An event withoutlinesis acknowledged and counted once (lines_absent): nothing was restocked and nothing was lost. - Poison. A
ReturnCompletedwhosedatadoes not decode, or that lacks a usableauthorizationId,nodeIdor instant, is dead-lettered toretailnetwork.customer-returns.events.dlqafter the same 5-attempt policy as the other consumers. A malformed line is never poison: it is skipped and counted. - No migration. The restock reuses the availability provenance pair
(
as_of,feed_id) the schema already stores; the pair's id column carries the id of the fact that last stamped availability — a feed id or, from here, a return authorization id. Nothing is renamed and no column is added, so there is no migration 0005 in this branch; the number stays free.
Consequences
- A closed return raises the owner listing's available quantity within the consumer lag; shoppers can buy the returned sellable units again without any vendor feed.
ListingAvailabilityChanged(and the listing views) can now carry an authorizationId where they carried only feed ids; tolerant consumers ignore the value, and the pair's meaning ("the fact that last set availability") is the additive reading. A feed after a restock replaces the quantity as always.- Two env/chart values gain a sibling:
CUSTOMER_RETURNS_CONSUMER_GROUPfromconfig.customerReturnsConsumerGroup(required, no default; the deploy setsoffer-availability-customer-returns), a fifth always-on loop, and the CR topic with its DLQ pre-created by warehouse-infra. - Unsellable units vanish from the sellable side by construction: they are never added anywhere.