Skip to content

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.

1234567891011121314CLIENTStorefrontEDGECDNSERVICEStore APIDATABASEPostgresCACHERedisEXTERNALPayment providerEXTERNALHosted searchQUEUEOrder queueWORKEROutbox relayWORKERFulfilmentworkerEXTERNALWarehouse 3PLEXTERNALEmail provider

Select a component to see what it is responsible for and which state it owns.

  1. 1Storefront → CDN: View product
  2. 2CDN → Store API: Render on miss
  3. 3Storefront → Store API: Add to cart
  4. 4Store API → Redis: Read/write cart
  5. 5Storefront → Store API: Place order
  6. 6Store API → Postgres: Reserve stock and create order
  7. 7Store API → Payment provider: Authorize payment
  8. 8Payment provider → Store API: Payment webhooks
  9. 9Outbox relay → Postgres: Read outbox
  10. 10Outbox relay → Order queue: Publish order placed
  11. 11Fulfilment worker → Order queue: Receive orders
  12. 12Fulfilment worker → Warehouse 3PL: Create shipment
  13. 13Fulfilment worker → Email provider: Send receipt
  14. 14Storefront → Hosted search: Search
  • Request / response
  • Asynchronous

Select a part to trace its flows.

  • Request / response
  • Asynchronous

Parts 12

Flows 14

  1. 1Storefront → CDNView productRequest / response
  2. 2CDN → Store APIRender on missRequest / response
  3. 3Storefront → Store APIAdd to cartRequest / response
  4. 4Store API → RedisRead/write cartRequest / response
  5. 5Storefront → Store APIPlace orderRequest / response
  6. 6Store API → PostgresReserve stock and create orderRequest / response
  7. 7Store API → Payment providerAuthorize paymentRequest / response
  8. 8Payment provider → Store APIPayment webhooksAsynchronous
  9. 9Outbox relay → PostgresRead outboxRequest / response
  10. 10Outbox relay → Order queuePublish order placedAsynchronous
  11. 11Fulfilment worker → Order queueReceive ordersRequest / response
  12. 12Fulfilment worker → Warehouse 3PLCreate shipmentRequest / response
  13. 13Fulfilment worker → Email providerSend receiptRequest / response
  14. 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