Design an Authenticated Shopping Platform
Design a single-retailer shopping API whose login, session, cart, and order boundaries remain secure and retry-safe at scale.
Problem statement
For this exercise, assume a single retailer operates an online shopping service. Anyone may search, filter, and sort an approximately current product-summary catalog of up to 10 million products and retrieve a product detail labeled with a stable version.
A shopper registers with normalized email and password, signs in, receives a signed audience-bound access token valid for 15 minutes plus an opaque rotating refresh session valid for up to 30 days, and can revoke one or all sessions.
Authenticated shoppers maintain a persistent cart; every idempotent add, update, or remove uses an expected cart version, successful mutations advance that version, and stale versions conflict.
Every cart and order API must enforce resource ownership from the authenticated identity rather than a caller-supplied user identifier.
Cart contents do not reserve stock. Order submission validates current product versions, durably records one recoverable pending order, and durably hands off a stable inventory-reservation command before any external inventory call.
A confirmed reservation advances that order to accepted, a confirmed refusal advances it to rejected, and an uncertain result leaves it pending. A shopper who loses a response can query the same outcome by the original idempotency key.
Passwords exist only as salted adaptive hashes, refresh secrets are stored only as hashes, and credentials or tokens never enter logs, analytics, or caches. The source workload is one million users per day and 10,000 orders per hour, and inventory remains an existing external API.
Design the database schema, public and internal APIs, authentication and authorization flow, catalog read path, cart and order write paths, failure recovery, and observability.
Product administration, payments, fulfillment, recommendations, returns, social login, enterprise federation, and multi-factor authentication are outside scope.
What to build
- A shopper can register, sign in, rotate a refresh session, log out, and revoke all sessions without exposing credential or token secrets.
- Any user can search, filter, and sort approximately current summaries across up to 10 million products and retrieve a versioned product detail.
- An authenticated shopper can read and idempotently add, update, or remove items only in that shopper's persistent cart by supplying an expected cart version; each successful mutation advances the version and a stale version conflicts.
- An authenticated shopper can idempotently submit the current cart and later recover one authoritative accepted, rejected, or pending order outcome without accessing another shopper's order.
At scale
- Source fact: support 10 million products, one million users per day, and 10,000 orders per hour while integrating an existing inventory API.
- Practice assumption: support bursts of 50,000 catalog reads, 5,000 login or refresh requests, 10,000 cart mutations, and 100 order submissions per second.
- Practice assumption: target 20 milliseconds p95 for product-side access-token validation, 300 milliseconds p95 for healthy login or cart operations, one second p95 for order admission, and 99.99 percent monthly availability for authentication APIs.
- Practice assumption: access tokens last 15 minutes, refresh sessions last at most 30 days, carts expire after 90 days of inactivity, audit evidence is retained for one year, and accepted order identity survives a single-zone failure.