System Design Atlas

B2B wholesale orders with credit limits

05 / 10Worked example

Authoritative data and states

How do stock and credit reservations both remain unchanged on rejection or a crash?

The interfaces require authoritative state. Order confirmation reserves stock and credit together. Available stock and remaining credit stay non-negative. Delivery replaces the credit reservation with a receivable and consumes reserved stock once. The table separates current states from the evidence that established them.

Starting point Bind the order to P-101 and the quantity.

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.

Data relationships and permitted transitions

Order, offer, two reservations and fulfilment

Offer P-10110 × 2000 cents
Order A-101eingegangen → bestätigt
Stock W-10115 − 10 = 5
Credit K-10130.000 − 20.000 = 10.000
Fulfilment requestoffen / Klärung / geliefert
eingegangen → bestätigt or abgelehntbestätigt → erfüllung_offen or stornierterfüllung_offen → geliefert or klärung

Stock and credit reservations belong to A-101; geliefert replaces the credit reservation with a receivable.

Stock is sufficient but credit is not. Perform both checks and reservations in one transaction. Rejection leaves no partial commitment.

Entities and relationships

EntityAuthoritative dataResponsibility
Order A-10110 boxes, P-101, 20,000 cents and stateReserves stock and credit together.
Offer P-101Items, unit price, end of validityImmutable price reference.
Stock W-10115 boxes and active reservationsAuthoritative for local commitments.
Credit line K-101Limit, outstanding receivables and active reservationsAvailable credit before the order: 30,000 cents.
Fulfilment requestOrder, external reference and evidencePrevents double handover.

Order A-101

Authoritative data
10 boxes, P-101, 20,000 cents and state
Responsibility
Reserves stock and credit together.

Offer P-101

Authoritative data
Items, unit price, end of validity
Responsibility
Immutable price reference.

Stock W-101

Authoritative data
15 boxes and active reservations
Responsibility
Authoritative for local commitments.

Credit line K-101

Authoritative data
Limit, outstanding receivables and active reservations
Responsibility
Available credit before the order: 30,000 cents.

Fulfilment request

Authoritative data
Order, external reference and evidence
Responsibility
Prevents double handover.

Permitted state transitions

Starting pointTargetCondition
eingegangenbestätigtPrice valid; 10 boxes and 20,000 cents reserved together.
eingegangenabgelehntAt least one commitment requirement is missing.
bestätigterfüllung_offenExternal fulfilment request created durably.
bestätigtstorniertBefore fulfilment starts, both reservations are released.
erfüllung_offengeliefertMatching delivery evidence; the credit reservation is atomically converted to a receivable.
erfüllung_offenklärungThe external outcome remains unknown.
geliefert or storniert or abgelehntterminalReturns and settlement are separate follow-up processes.

eingegangen

Target
bestätigt
Condition
Price valid; 10 boxes and 20,000 cents reserved together.

eingegangen

Target
abgelehnt
Condition
At least one commitment requirement is missing.

bestätigt

Target
erfüllung_offen
Condition
External fulfilment request created durably.

bestätigt

Target
storniert
Condition
Before fulfilment starts, both reservations are released.

erfüllung_offen

Target
geliefert
Condition
Matching delivery evidence; the credit reservation is atomically converted to a receivable.

erfüllung_offen

Target
klärung
Condition
The external outcome remains unknown.

geliefert or storniert or abgelehnt

Target
terminal
Condition
Returns and settlement are separate follow-up processes.

Change reservations together

Change reservations together

Perform both checks and reservations in one transaction.

Stock is sufficient but credit is not.

Rejection does not leave a half-commitment.

Alternative considered
Two independent reservations require compensation.
Trade-off
The shared write datastore constrains separation.
Reassess
Independent warehouses require a distributed commitment contract.

Terms in this step

Change reservations together
Rejection does not leave a half-commitment.

Try it yourself

Stock is sufficient but credit is not. State the permitted changes and the outcome of a crash before commit.

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
The transaction rejects the entire order; stock and credit reservations remain unchanged.
Second part of the solution
A crash before commit likewise leaves no partial reservation. Both resources are checked and changed together.

Apply to your project

Which corresponding assumption would you test first in your project? Consider this trigger: Independent warehouses require a distributed commitment contract.

Step 6 examines fulfilment after the commitment.