System Design Atlas

Grocery orders with store inventory and substitutions

05 / 10Worked example

Data and states

What values change in the case of a replacement and a later restocking?

The interfaces require a authoritative data state. P denotes the shelf forecast in packs, Z the still unpicked online allocations. The display calculates max(0,P−Z). After an allocation for B-17, the original applies P=1 and Z=1. Only a confirmed pick moves the pack from the shelf forecast to the goods receipt of the order.

Starting point The commands from step 4 need a authoritative shared order and goods status.

Assumptions for the example case

Own example design for pick-up from a store and packaged piece goods with strictly positive integer cent prices. Free and fully discounted baskets are outside the case. Replacement items are specifically allowed in advance; the final positive amount arises from goods actually provided and is collected on collection. Figures and target values are illustrative design assumptions.

The package shall change its proof

P, Z and pick · each pack retains domain evidence

Shelf forecast per store/itemA-10 P=1 · A-11 P=2
Open allocation per order itemB-17 / A-10: Z=1
Pick proof per order itemItem, quantity, price, restocking status

Original pick · a transactionP−1 · Z−1 · Pick +1

Replacement pick · a transactionOriginal empty: P=0,Z−1 · Replacement: P−1 · Pick A-11

Restock the item actually pickedonly after physical confirmation +1, one-time; no reserve edge to A-10
Before: A-10 P=1,Z=1 · A-11 P=2,Z=0After replacement: A-10 P=0,Z=0 · A-11 P=1,Z=0After restocking: A-10 P=0,Z=0 · A-11 P=2,Z=0

The substitute pick corrects the original shortage to P=0, releases its allocation and records the substitute stock decrease. Subsequent restocking increases only A-11, at most once, after physical confirmation.

Shelf forecast, open allocation and pick proof remain separate. Replacement and physically confirmed restocking only change the respective evidenced item states.

Entities and Authoritative relationships

EntityAuthoritative fieldsRelationship and purpose
OrderStore, version, condition, frozen amountConnects order lines, payment and issuance of a store.
Order lineOriginal, Quantity, Replacement Release, ConclusionEnds as picked or left out.
AllocationItem, article, open quantityForms Z as the sum of active unpicked allocations.
Picking recordItems, quantity, positive cent price, restocking statusEvidences the goods actually picked and any later restocking.
Stock movementSource, event identifier, sequenceLeads orderly and deduplicated store stock movements.
Payment instructionE-17, B-17, frozen amount, EUR, external reference, resultTies each confirmation to order, payment instruction, amount and currency.
Command resultActor, operation, order, content hash, resultMakes repetitions after disconnection clear.
Outbox and InboxOrder or feedback, status, deduplicationConveys external work and accepts feedback permanently.

Order

Authoritative fields
Store, version, condition, frozen amount
Relationship and purpose
Connects order lines, payment and issuance of a store.

Order line

Authoritative fields
Original, Quantity, Replacement Release, Conclusion
Relationship and purpose
Ends as picked or left out.

Allocation

Authoritative fields
Item, article, open quantity
Relationship and purpose
Forms Z as the sum of active unpicked allocations.

Picking record

Authoritative fields
Items, quantity, positive cent price, restocking status
Relationship and purpose
Evidences the goods actually picked and any later restocking.

Stock movement

Authoritative fields
Source, event identifier, sequence
Relationship and purpose
Leads orderly and deduplicated store stock movements.

Payment instruction

Authoritative fields
E-17, B-17, frozen amount, EUR, external reference, result
Relationship and purpose
Ties each confirmation to order, payment instruction, amount and currency.

Command result

Authoritative fields
Actor, operation, order, content hash, result
Relationship and purpose
Makes repetitions after disconnection clear.

Outbox and Inbox

Authoritative fields
Order or feedback, status, deduplication
Relationship and purpose
Conveys external work and accepts feedback permanently.

A relational transaction store supports the relationships and atomic multi-line changes of the replacement pick. An outbox contains, together with the domain change, stored orders that are still to be transmitted. An inbox contains permanently accepted feedback.

Stock rules and evidenced store reconciliation

New allocation and confirmed pick
A new original-item allocation atomically checks P−Z≥quantity and increases Z. A physically confirmed original pick reduces P and Z together. Delayed in-store sales can make P negative; the display remains max(0,P−Z), and the negative state requires investigation.
Replacement protects existing allocations
The scanned substitute satisfies the approved item, quantity and positive price. Approval also checks its P−Z≥quantity against other allocations and requires a gap-free or fully reconciled feed. Lock the order and both item rows in a stable order. The transaction sets P for the confirmed empty original shelf location to zero, releases its own allocation, records the substitute stock decrease and stores the pick record.
Restocking needs physical confirmation
Cancellation releases unpicked allocations without increasing P. Picked goods increase the forecast for the item actually picked exactly once, and only after confirmed return to saleable stock. Disposal completes goods resolution without increasing stock.
Sequence of events in the inventory management
The agreed feed supplies an event identifier and a gap-free increasing sequence for each store. It excludes online picks and their restocking so local stock movements remain unique. A sequence gap blocks new original-item commitments and substitute picks for that store until full reconciliation is complete.
A common cut for full adjustment
The snapshot contains lastIncludedSequence and forecast values for both items. It includes all POS movements up to that sequence watermark, plus all previously confirmed local online picks, shortage corrections and restocking. Block affected item changes while establishing this common snapshot boundary. Preserve open allocations Z; subsequent events resume at watermark plus one. An outdated inventory-system snapshot that excludes online movements must not replace P. Producing this common snapshot remains an open integration requirement.

Allowed states and transitions

Starting pointPermitted transitionCondition or result
angenommenin_kommissionierungThe store team begins the processing.
Accepted or in_CommissionedbereitAll order lines are closed and at least one order line is picked; the positive amount is frozen.
Accepted or in_Commissionedabbruch_in_klaerungAll order lines are omitted or the termination begins before a payment instruction.
bereitabbruch_in_klaerungCancellation is possible before a permanently stored payment instruction. Picked goods remain bound until the confirmed restocking or disposal.
bereitzahlung_offenE-17 is permanently stored for B-17, the positive frozen amount and EUR.
zahlung_offenbezahltAn authenticated confirmation matches B-17, E-17, amount and EUR.
zahlung_offenzahlung_fehlgeschlagenThe payment service confirms a definitive refusal.
zahlung_offenzahlung_offenAn unknown result remains open with a visible clearing ground.
zahlung_fehlgeschlagenabbruch_in_klaerungThe handover remains blocked; picked goods are clarified.
abbruch_in_klaerungabgebrochenAll allocations are released, picked packs are restocked or disposed of, and evidence confirms that no charge occurred.
bezahltausgegebenThe issuance of the same order is confirmed once.
bezahltbezahltMissing handover remains visible as an open customer service case.
Issued or terminatedterminalMore new picks, payment starts and handovers do not produce any effect; identical old repetitions provide their saved result.

angenommen

Permitted transition
in_kommissionierung
Condition or result
The store team begins the processing.

Accepted or in_Commissioned

Permitted transition
bereit
Condition or result
All order lines are closed and at least one order line is picked; the positive amount is frozen.

Accepted or in_Commissioned

Permitted transition
abbruch_in_klaerung
Condition or result
All order lines are omitted or the termination begins before a payment instruction.

bereit

Permitted transition
abbruch_in_klaerung
Condition or result
Cancellation is possible before a permanently stored payment instruction. Picked goods remain bound until the confirmed restocking or disposal.

bereit

Permitted transition
zahlung_offen
Condition or result
E-17 is permanently stored for B-17, the positive frozen amount and EUR.

zahlung_offen

Permitted transition
bezahlt
Condition or result
An authenticated confirmation matches B-17, E-17, amount and EUR.

zahlung_offen

Permitted transition
zahlung_fehlgeschlagen
Condition or result
The payment service confirms a definitive refusal.

zahlung_offen

Permitted transition
zahlung_offen
Condition or result
An unknown result remains open with a visible clearing ground.

zahlung_fehlgeschlagen

Permitted transition
abbruch_in_klaerung
Condition or result
The handover remains blocked; picked goods are clarified.

abbruch_in_klaerung

Permitted transition
abgebrochen
Condition or result
All allocations are released, picked packs are restocked or disposed of, and evidence confirms that no charge occurred.

bezahlt

Permitted transition
ausgegeben
Condition or result
The issuance of the same order is confirmed once.

bezahlt

Permitted transition
bezahlt
Condition or result
Missing handover remains visible as an open customer service case.

Issued or terminated

Permitted transition
terminal
Condition or result
More new picks, payment starts and handovers do not produce any effect; identical old repetitions provide their saved result.

The direct transition from angenommen to bereit is a shortened main path. Cancellation does not recreate missing original stock.

Case decision and verification approach

atomic replacement pick

Order, both ordered locked inventory lines, pick and command result change in a short transaction.

A replacement takes another item and at the same time ends the original allocation.

Both pages of articles must fit together after a crash. Before commit, everything remains unchanged; after commit, both changes and the result are visible.

Alternative considered
Sequential bookings can generate half-finished replacements.
Trade-off
Two item rows are briefly blocked.
Reassess
Measurable waiting times for replacement give rise to the investigation of lock duration and query order.

Terms in this step

Shelf forecast P
The locally managed forecast value per store and item.
Open allocations Z
The sum of active, still unpicked online allocations.
Picking record
The immutable evidence of actually picked items, quantity and price.

Try it yourself

Start with original P=1, Z=1 and substitute P=2, Z=0. The original shelf location is empty and the permitted substitute is picked. State all four values. Then cancel and report completed restocking of the substitute twice.

A hint for your attempt

An allocation counts unpicked goods; the restocking relates to the item actually picked.

Compare with a possible solution
Replacement pick
After the replacement, the original is P=0, Z=0 and the replacement is P=1, Z=0.
Termination request
The desire to abandon alone does not change the forecasts.
Confirmed restocking
The first physically confirmed restocking gives P=2 for the replacement; the repetition remains ineffective. The original remains at P=0.

Apply to your project

Which two state changes must be visible together in your draft?

Step 6 assigns this responsibility to runtime modules.