System Design Atlas

B2B wholesale orders with credit limits

04 / 10Worked example

Change commands and retries

Which price applies when retrying an already accepted order?

Scale alone does not ensure consistent retry behaviour. This proposed API binds the role, business object, change payload and expected state to each new intent. An idempotency key identifies the same intent after a response is lost.

Starting point Calculate order totals as integer cents.

Assumptions for the example case

A fictional example design with one customer, one currency and one warehouse; a binding price offer; complete local stock and credit reservations; and one complete delivery. Figures and quality goals are illustrative test assumptions. Multiple currencies, tax calculation, partial delivery and credit insurance are outside the scope.

Retries and new intent

Order envelope and stored response

Order envelopeA-101 · P-101 · 10 × 2000
Auftragsumschlag → SchlüsselprüfungrequestKey + content
Key validationIdentical / changed / new
Identical → historical confirmation11 boxes → conflictnew → joint commitment check

Reusing a key with identical content returns the confirmation; eleven boxes under the same key produce a conflict.

The price changes during a retry. Bind the order to P-101 and quantity. A retry does not adopt a new price version.

Proposed domain API contracts

  1. POST/wholesale-orders

    Commit stock and credit together.

    Input
    Customer purchasing, K-101, P-101, W-101, quantity 10 boxes, expected offer version and key. The server calculates 20000 cents.
    Result
    A-101 with joint stock and credit reservations, or complete rejection; no partial commitment.
    Retry behaviour
    An identical operation by the same authorised role on the same object, using the same key and canonical payload, returns the stored original result. A changed payload under that key is rejected. External result identifiers are durably deduplicated after authentication; new intents check the current version again.
  2. POST/wholesale-orders/{id}/fulfillment

    Hand a confirmed order over for fulfilment.

    Input
    Order support, A-101, expected version and key.
    Result
    202 with a durable fulfilment request; amount and quantity come from the confirmed commitment.
    Retry behaviour
    An identical operation by the same authorised role on the same object, using the same key and canonical payload, returns the stored original result. A changed payload under that key is rejected. External result identifiers are durably deduplicated after authentication; new intents check the current version again.
  3. POST/wholesale-orders/{id}/cancel

    Cancel before fulfilment starts.

    Input
    Authorised purchasing or order support, A-101, version, reason and key.
    Result
    Cancellation releases both reservations together. An existing open fulfilment request causes a conflict and investigation.
    Retry behaviour
    An identical operation by the same authorised role on the same object, using the same key and canonical payload, returns the stored original result. A changed payload under that key is rejected. External result identifiers are durably deduplicated after authentication; new intents check the current version again.
  4. POST/delivery-evidence

    Record delivery and its receivable reference.

    Input
    Authenticated inventory management, unique delivery record, fulfilment reference, A-101, 10 boxes, 20000 cents, EUR and invoice reference.
    Result
    Consume stock once and atomically replace the credit reservation with a receivable; discrepancies remain unresolved.
    Retry behaviour
    An identical operation by the same authorised role on the same object, using the same key and canonical payload, returns the stored original result. A changed payload under that key is rejected. External result identifiers are durably deduplicated after authentication; new intents check the current version again.
  5. GET/wholesale-orders/{id}

    Read commitment and fulfilment state.

    Input
    Role authorised for the object, A-101.
    Result
    Offer, stock reservation, credit reservation, receivable and outstanding external evidence.
    Retry behaviour
    Repeating a read creates no business effect; the returned current state may change between requests.

Preserve the offer

Preserve the offer

Bind the order to P-101 and the quantity.

The price changes during a retry.

Retry does not adopt a new price version.

Alternative considered
Reading the current price on every retry changes the original intent.
Trade-off
Expired offers need new confirmation.
Reassess
Dynamic prices are explicitly introduced.

Terms in this step

Preserve the offer
Retry does not adopt a new price version.

Try it yourself

P-101 expires and A-101 is retried identically. Distinguish the original result from a new order.

A hint for your attempt

Use the specific entities and conditions from this step. The two solution parts distinguish the decision from its evidenced outcome.

Compare with a possible solution
First part of the solution
An identical retry of an accepted order returns its stored confirmation against P-101.
Second part of the solution
A new order after offer expiry requires a valid offer; it cannot silently reuse the old price.

Apply to your project

Which corresponding assumption would you test first in your project? Consider this trigger: Dynamic prices are explicitly introduced.

Step 5 examines atomic reservation changes.