KatInterview

Secure Storefront Backend: Accounts, Carts and Safe Checkout

System DesignModel answer
MediumModel answerSystem Designauthenticationauthorizationidempotency

Last updated

Design a storefront backend where users sign up, log in, browse products, manage a personal cart and place orders safely, while APIs block access to other users' data.

Problem

You are designing the backend for an online store in which identity and access control are the central concerns. Walk through the following capabilities and the design decisions behind them:

  • Account creation and login
  • How a logged-in client proves who it is on later requests (server sessions or tokens)
  • Browsing the product catalog
  • A cart that belongs to one user
  • Turning a cart into an order

You must also explain how each API ensures that one customer can never view or modify another customer's carts or orders.

Assumptions

  • Passwords must never be stored in plaintext.
  • The owner of a cart or order is taken from the authenticated identity on the request, never from a user ID the client sends in the body or URL as a source of truth.
  • Placing an order must be safe to retry, for example when the client times out and sends the request again.
  • Payment is out of scope. Checkout only needs to produce an order in a pending state.

Questions you may want to raise

  • Should the client use server-side sessions, or short-lived access tokens with rotating refresh tokens?
  • Do anonymous (guest) carts need to exist, and if so how are they merged into the account cart at login?
  • Which operations are limited to administrators or other elevated roles?

What to deliver

Describe the data model, the main API endpoints, the authentication and session lifecycle, the authorization approach, the checkout flow with its retry protection, the main attack surfaces and their mitigations, and how you would test and monitor the system.

Hints

Hint 1

Start with who the caller is (authentication) and then what they may touch (authorization). Ask which identity the server trusts: the one it derived from the credential, not one in the request payload.

Hint 2

For retries, think about a client-generated unique key stored with a uniqueness constraint, so a repeated request returns the original result rather than creating a second order.

Hint 3

An order should not point at live product rows for its prices. Consider copying the item names, prices and quantities at checkout time, inside a single database transaction with the cart clearing.

Hint 4

List the attacks by layer: credential stuffing and enumeration at login, session fixation and theft, CSRF for cookie-based auth, and IDOR (accessing another user's object by guessing its ID) on cart and order endpoints.