KatInterview

Scalable Backend for a High-Traffic Book Retail Platform

System DesignModel answer
HardModel answerSystem Designsystem-designe-commerceinventory

Last updated

Design the backend of a book-selling website that survives flash sales, with fast search, no overselling of stock, and safe recovery when payment and inventory steps fail partway.

Build the Backend for a Book Retail Website

You are asked to design the server side of a web store that sells books to millions of shoppers. Traffic is normally steady but spikes sharply during promotions, and the system must stay up when individual components break.

What the product must do

  • Shoppers find books by title, author, or genre.
  • Shoppers open a book page showing details, price, and whether it is in stock.
  • Shoppers fill a cart and check out.
  • Staff can change stock counts and prices.

Quality goals

  • Availability: a failing component should not take down the whole store.
  • Elasticity: sudden surges, such as a limited-time sale, must be absorbed.
  • Consistency: stock counts must never allow selling more copies than exist. Search results may trail the truth by a few seconds.

Please address

  1. Service boundaries: which services exist and what each owns.
  2. Storage choices: for the catalog, user accounts, and order history, with reasons.
  3. Search: how books are indexed and kept up to date to support fast, flexible queries.
  4. Concurrent purchases: how you stop many buyers of the same title from corrupting the stock count.
  5. Partial failures: what happens when, for example, the card is charged but the stock update fails, and how the system recovers.

State your traffic assumptions with numbers before you design.

Hints

Hint 1

Split the system into a read-heavy browse/search side that tolerates staleness and a write-heavy checkout side that must be exactly right, and spend most of your effort on the second.

Hint 2

For stock, compare locking approaches. A single conditional UPDATE (decrement only if enough remains) avoids both long locks and retry storms. Pair it with time-limited reservations so no lock is held while calling the payment provider.

Hint 3

For failures, think saga plus idempotency: each step has a compensating action, requests carry an idempotency key, and a reconciliation job repairs anything left half-finished (for example, a charge with no committed stock).