← Lessons

quiz vs the machine

Silver1080

System Design

Cart and Checkout State

Where the cart lives and how checkout progresses.

4 min read · intro · beat Silver to climb

Two kinds of state

  • A cart is long lived and forgiving. It can be lost without much harm and is often stored per user or per session.
  • A checkout is short lived and strict. It captures address, shipping, payment, and must move through clear steps.

Where the cart lives

  • Client only: fast but lost across devices.
  • Server keyed by user: survives device switches and powers reminders.
  • Hybrid: a guest cart in the browser that merges into the server cart on sign in.

Checkout as a state machine

Checkout moves through states such as started, address set, payment authorized, and confirmed. Each transition is explicit so you can resume an interrupted checkout and avoid charging without an order.

Key idea

Keep the cart durable and forgiving, and model checkout as an explicit state machine so each step is resumable and no payment happens without a confirmed order.

Check yourself

Answer to earn rating on the learn ladder.

1. How do a cart and a checkout differ?

2. Why model checkout as a state machine?