System Design Atlas

Grocery orders with store inventory and substitutions

06 / 10Worked example

Overall architecture

Which boundaries support operation, and which make domain responsibilities understandable?

The data model requires joint local decisions and a separate approach to external effects. We start with an order API and a background process from the same application. Domain modules structure the code. They are not individually operated services here. The background process reads permanently earmarked work and compares open payments.

Starting point The atomic replacement change from step 5 determines which data must be reachable together.

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.

Runtime components and external boundaries

Seven nodes · twelve directed relationships · one backend boundary

Customer interfaceGroceries, substitution approvals, status
Store interfacePick, restock, hand over

Back end limit · Order application

Order APIContracts, authorisation, atomic domain changes, webhook acceptance
Background processOutbox, feed import, payment reconciliation, clearance lists
Transactional storeOrder, P/Z, Picks, Commands, Inbox/Outbox, Payment Order
Inventory managementagreed ordered movement feed
Payment serviceCharge and confirmed payment status
  1. 01Customer interface → Order APIOrder/Read status
  2. 02Order API → Customer interfaceBasket and status
  3. 03Store interface → Order APIPick / restock / hand over
  4. 04Order API → Store interfaceResult / Conflict / Release
  5. 05Order API → Transactional storeAtomic Commands / Inbox
  6. 06Transactional store → Order APICommit / authoritative state
  7. 07Background process → Transactional storeRead Outbox, Feed and Save Results
  8. 08Transactional store → Background processOpen instructions / sequence watermark
  9. 09Inventory management → Background processOrderly branch movements
  10. 10Background process → Payment serviceExecute E-17 / Reconcile status
  11. 11Payment service → Background processResponse / confirmed status
  12. 12Payment service → Order APISigned feedback

Order API and background process belong to the same application. Local decisions share the transactional store; external effects remain orders in need of confirmation.

Customer and store interface use order API and background process with shared transactional store. Inventory management and payment service form the external borders.

Open the order API technically

Inside the order API · five domain modules in one process

Process framework · Order API

OrderTracks version, order lines and basket
Store availabilityAllocates and records picking or restocking
Substitution checkChecks item, quantity and price
Payment and handoverTracks E-17 and the single handover
Cases requiring reviewkeeps goods and payment work visible
  1. 01Order → Substitution checkChecking item/quantity/price
  2. 02Order → Store availabilityAllocate / record pick
  3. 03Order → Payment and handoverTransfer frozen basket
  4. 04Payment and handover → Cases requiring reviewReport unresolved charge
A transactional store Replacement pick changes order, both article lines, pick and command result together.

The modules organise domain responsibilities. They collaborate through local calls and require no network service.

The order API subdivides order, store availability, replacement checking, payment and handover as well as cases requiring review into domain modules with joint local data management.

Case decision and verification approach

Modular monolith

Start with a modular monolith, separately running background processing and shared storage.

The replacement pick must change the order status and two item statuses together.

The local transaction remains manageable. A process restart after commit must not lose the outbox order.

Alternative considered
Separate inventory and ordering services require an additional distributed commitment contract.
Trade-off
Schema changes and releases remain coordinated.
Reassess
Independent teams, significantly different loads or evidenced availability requirements justify a new service limit.

Terms in this step

Modular monolith
A jointly operated application with technically separate modules and local atomic changes.
Background process
A dedicated runtime process for permanently earmarked transmission, feed import, payment reconciliation and clarifying lists.

Try it yourself

Assign substitution checking, the background process and the payment service to module, runtime process and external system. Justify shared storage for the substitute pick.

A hint for your attempt

A technical task does not automatically need its own network connection.

Compare with a possible solution
Domain module
The replacement check is a module within the order API.
Runtime process
The background process runs independently and continues permanent work.
External border and storage
The payment service is an external system. The shared local data storage allows both item stands and the pick to be changed atomically; the external payment remains an order in need of confirmation.

Apply to your project

Which boundary solves a specific operational problem in your system?

Step 7 tracks the most difficult error point through precisely these building blocks.