Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Budget-Capped Book Purchase Across Many Sellers

Design a service that buys one copy of a book for a user from many outside sellers: it asks every seller for a price, orders from one that fits the user's budget and charges the user once, with deep dives on telling a double click from a wanted second copy, on placing the order and taking the payment while tracking the order's state, and on how sellers join.

Problem statement

Design a book-buying service. The user enters a book's ISBN (the standard number that identifies one edition of a book) and the most they are willing to pay. The service then asks about 50 book sellers what they would charge.

When a price comes in under that budget, the service places the order itself; the user does not confirm it.

For this exercise, assume: - The service keeps no books of its own. The sellers are separate businesses that join the platform, and the service buys from them on the user's behalf. - One request buys one copy, paid with a card the user saved earlier. The platform charges the user and pays the sellers later.

- Every seller offers a price call and an order call in a format the platform defines. A price covers the book plus shipping to the user's address and stays valid for a few minutes. - When several sellers are under the budget, the service buys from the cheapest one that answers within a short wait.

When none is, nothing is bought and nothing is charged.

Start with the user-facing API, the data model and the architecture.

The deep dives then cover duplicate orders (how to tell an accidental double click from a user who really wants another copy, and which steps must be idempotent, meaning safe to repeat with the same result), placing the order and taking the payment together with tracking the order's state, and how a new seller registers.

For this exercise, assume catalog search, shipping, returns after delivery and paying the sellers stay outside this design.

What to build

  1. A user asks to buy one copy of a book by ISBN with a budget. The service gets prices from the sellers and, if one fits the budget, orders from the cheapest such seller and charges the user that price.
  2. The user can follow a purchase from the moment it is sent, and every purchase reaches one clear result: the book is ordered (and later shipped and delivered), no seller fit the budget, the card was declined, or the purchase failed with nothing charged.
  3. One purchase request buys at most one copy and charges the user at most once, even when the user clicks twice or a step is retried. A user who really wants a second copy can still buy one.
  4. For this exercise, a seller can sign up, connect its price and order calls, and start getting price requests only after the platform has checked that those calls work.

At scale

  • For this exercise, assume about 500,000 purchase requests a day, with a peak of about 30 a second, and that each request asks all of the roughly 50 sellers for a price.
  • For this exercise, assume most sellers answer a price request within 1 second, a few are slow or down at any time, and an order call may need up to about 10 seconds; in the usual case the user should see the outcome (ordered, or no offer within the budget) within about 5 seconds.
  • For this exercise, assume a request must never buy two copies or charge the user twice, and the user is never charged more than the budget.