Examples/Commerce
Online store (example)
A store with a product catalog, cart, checkout, inventory and fulfilment. Postgres holds stock and orders, Redis holds carts, and an outbox relay publishes orders to SQS for fulfilment. Replace any part with how your own system works.
Scale: 50k orders/day, 20x spikes on sale days.
Select a component to see what it is responsible for and which state it owns.
- 1Storefront → CDN: View product
- 2CDN → Store API: Render on miss
- 3Storefront → Store API: Add to cart
- 4Store API → Redis: Read/write cart
- 5Storefront → Store API: Place order
- 6Store API → Postgres: Reserve stock and create order
- 7Store API → Payment provider: Authorize payment
- 8Payment provider → Store API: Payment webhooks
- 9Outbox relay → Postgres: Read outbox
- 10Outbox relay → Order queue: Publish order placed
- 11Fulfilment worker → Order queue: Receive orders
- 12Fulfilment worker → Warehouse 3PL: Create shipment
- 13Fulfilment worker → Email provider: Send receipt
- 14Storefront → Hosted search: Search
- Request / response
- Asynchronous
Select a part to trace its flows.
- Request / response
- Asynchronous
Parts 12
Flows 14
- 1Storefront → CDNView productRequest / response
- 2CDN → Store APIRender on missRequest / response
- 3Storefront → Store APIAdd to cartRequest / response
- 4Store API → RedisRead/write cartRequest / response
- 5Storefront → Store APIPlace orderRequest / response
- 6Store API → PostgresReserve stock and create orderRequest / response
- 7Store API → Payment providerAuthorize paymentRequest / response
- 8Payment provider → Store APIPayment webhooksAsynchronous
- 9Outbox relay → PostgresRead outboxRequest / response
- 10Outbox relay → Order queuePublish order placedAsynchronous
- 11Fulfilment worker → Order queueReceive ordersRequest / response
- 12Fulfilment worker → Warehouse 3PLCreate shipmentRequest / response
- 13Fulfilment worker → Email providerSend receiptRequest / response
- 14Storefront → Hosted searchSearchRequest / response
Invariants 3
Stock never goes below zero
UPDATE inventory SET available = available - $qty WHERE sku = $1 AND available >= $qty inside the order transaction; zero rows means out of stock.
Kept by
An order is charged at most once
Order row created in 'pending' first; the payment call uses idempotency key = order id.
Kept by
Every committed order reaches fulfilment
Outbox row written in the order transaction; the relay retries until SQS accepts; fulfilment dedupes by order id.
Kept by