MentorNode
Start free
Commerce, Payments & LedgersMediumdesign-ecommerce-checkout

Design an E-Commerce Cart & Inventory Reservation

Design cart-to-order for a large catalog: persistent carts across devices, inventory counts that are read constantly and decremented atomically, and checkout that survives partial failure.

Cart Session StateInventory ReservationEventual ConsistencyCompensating Actions
Traffic & Capacity Estimates:

50M SKUs · 500k active carts · 2k orders/second · 1000:1 read:write on inventory

Functional Requirements

  • •Persist a cart per user across devices and sessions, merging guest carts on login.
  • •Show stock availability on product pages and reserve stock at checkout.
  • •Create an order atomically with reservation, payment, and confirmation.
  • •Release reservations automatically when checkout is abandoned.

Non-Functional Requirements

  • •Product page reads must be served from cache — inventory freshness of a few seconds is acceptable there.
  • •Reservation at checkout must be exact — overselling is not.
  • •A payment failure must release inventory within seconds, not at the next sweep.

Back-of-the-Envelope Math

  • 500k active carts * 5 KB = 2.5 GB — small enough to live entirely in the cache tier with durable backup.
  • 2k orders/s * 3 items = 6k atomic inventory decrements/second, concentrated on popular SKUs.

Key Architectural Trade-offs

  • Displayed stock can be stale and cached; reserved stock cannot — splitting the two is what makes a 1000:1 read ratio affordable.
  • Reserve-on-add-to-cart protects the buyer and strands inventory; reserve-at-payment maximizes availability and produces 'sold out at checkout'.
  • Cart in the cache is fast and loses data on eviction; cart in the database survives and costs a write on every interaction — write-behind splits the difference.

Click or drag a component onto the canvas, then connect the handles to draw the data flow.

3 nodes · 2 edges

Components · 35

Client & Edge4
Compute & Gateway7
Storage & Caching11
Messaging & Streaming6
Coordination & Ops5
Intelligence2
Canvas overview