E-Commerce Platform

Catalog, search, cart, checkout and orders

Design an online store with a large catalog, faceted search, a cart, stock held in several warehouses, and a checkout that never sells stock it does not have or charges a card twice.

Overview

An online store lets shoppers find products, put them in a cart and buy them. Behind that are two very different workloads. Browsing (product pages, search, category lists) is almost all reads: with the numbers assumed here, about 625 page views and searches for every order. Buying (checkout, stock, payment) is a small share of traffic, but it moves money and physical goods, so it must be correct.

A strong answer keeps the two apart. Browsing is served from caches, replicas and a search index that may be a second or two behind. Buying goes to a transactional store that decides, one row at a time, whether stock is really there. The interviewer usually probes the catalog model, how search stays fresh, how a price is fixed at checkout, how stock in several warehouses is reserved, and what happens when checkout fails halfway.

This topic is the generic store. The Amazon E-commerce topic goes deeper on an always-writable cart and one very hot item, and the Flash Sale System topic on a sale where a crowd arrives at one instant.

Questions to ask first

  • How many shoppers and orders? — 50 million daily active shoppers; 2 million orders a day
  • How big is the catalog? — 100 million SKUs (each size and color of a product is its own SKU)
  • Where is the stock? — Several warehouses; an order ships from one, or is split
  • Can we oversell? — No. A confirmed order has stock reserved behind it
  • When is stock held? — At checkout, for 15 minutes; never while an item only sits in a cart
  • Payments? — An external payment processor: authorize at checkout, capture at shipment
  • How spiky? — Sale days reach 10 times the average

What you will be able to do

  • Model products, variants and attributes so both the product page and filters work.
  • Keep a search index fresh from the catalog without losing updates.
  • Fix a cart's price at checkout, in whole cents, and explain what the shopper sees when it changes.
  • Reserve stock across several warehouses without overselling, and release it when a checkout is abandoned.
  • Run checkout as a saga with authorize-then-capture payments, and publish order events reliably with an outbox.

Key concepts

  • Products and SKUs
  • Search indexing pipeline
  • Facets
  • Price snapshot
  • Available to promise
  • Stock reservation
  • Checkout saga
  • Authorize and capture
  • Transactional outbox

Functional requirements

  • Show a product page with its variants, price and availability
  • Search the catalog by text, with filters (brand, size, price) and counts per filter value
  • Add, change and remove cart items; show an up-to-date total with promotions and tax
  • Check out: reserve stock, authorize payment, and return an order number
  • Show order status from confirmed to shipped and delivered; let the shopper cancel before shipment

Non-functional requirements

  • Product pages and search answer in under 200 ms at p99 (a target we chose)
  • Browsing stays up when checkout or payments are degraded
  • Never confirm an order without stock reserved for it
  • A retried checkout never creates a second order or a second charge
  • Catalog changes appear in search within about a minute (a target we chose)

Interview questions

  • How do you prevent overselling?
  • Walk me through checkout. What happens if payment fails halfway?
  • How does search stay in sync with the catalog?
  • Why store money as integer cents?
  • Where do you keep the cart, and does it hold stock?
  • Why authorize at checkout and capture at shipment?
  • How do other systems learn that an order was placed, without slowing checkout?
  • How would you scale the transactional store?

Sign up free to read the full topic

More System Design topics

Start free on Cariara · Coding problems · System design studio