KatInterview

Build a Scalable Storefront for Selling Books Online

System DesignModel answer
HardModel answerSystem Designsystem-designe-commerceinventory

Last updated

Design a book-selling web platform covering catalog search, cart, checkout and orders, with emphasis on inventory correctness, idempotent payments, caching, and fault tolerance.

You are asked to design the backend for an online shop that sells books. Customers must be able to look through the catalog and buy items.

In your answer, cover the following:

  1. Requirements. Ask clarifying questions and separate functional needs from non-functional ones (latency, availability, consistency, security). State what you consider out of scope.
  2. Scale assumptions. Estimate traffic, order volume, catalog size and storage.
  3. APIs. Define endpoints for search and browsing, product detail, cart, checkout, payment, and order history.
  4. Data model. Cover books, authors, inventory, pricing, users, carts and orders.
  5. Architecture. Describe service boundaries, the choice between SQL and NoSQL for each store, search indexing, caching and CDN usage, and the main read and write paths.
  6. Checkout correctness. Explain how stock is reserved and kept consistent during purchase, and how order and payment creation stay idempotent.
  7. Cross-cutting concerns. Security and privacy, observability, capacity planning, scalability, availability and fault tolerance.

Be explicit about trade-offs and about what happens when components fail.

Hints

Hint 1

Estimate first: browsing is read-heavy (on the order of 100:1) while purchasing is rare but must be exactly right. Treat these as two different problems, caching and search for one, correctness for the other.

Hint 2

Treat checkout as a multi-step workflow with explicit states (order created, stock reserved, payment authorized, confirmed) and a compensating action for each step. Reserve stock with a single conditional atomic update, and give reservations an expiry.

Hint 3

Every write that can be retried (order creation, payment) needs a client-supplied idempotency key backed by a unique constraint. For events, write to an outbox table in the same transaction as the state change instead of writing to the DB and the message bus separately.