Design an Online Bookstore System
Company: Databricks
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Onsite
Design a bookstore system. The report gives only this one-word prompt, so settle the scope with the interviewer first. A common reading is an online bookstore: customers browse and search a catalog of books, see prices and availability, add books to a cart, check out and pay, and the store tracks inventory and fulfils orders.
```hint The last copy
Decide when stock is set aside for a customer, and what happens when two customers try to buy the last copy of a book at the same moment.
```
```hint Browsing is not buying
Traffic to browse and search is much larger than traffic to buy. Decide which data can be served from caches or a search index, and which must be read from the source of truth.
```
### Constraints and Clarifications
- Not given: catalog size, traffic, physical or electronic books, one seller or many, regions, and which features beyond buying are in scope. Ask, or state your assumptions.
### Clarifying Questions
- Physical books shipped from warehouses, e-books, or both? One store or a marketplace of sellers?
- How many titles, daily visitors and orders a day, and what peaks (a major release, holiday sales)?
- Which features are in scope: search, reviews and ratings, recommendations, wishlists, pre-orders?
- How many warehouses, and may the store oversell and backorder?
- Is payment handled by an external payment provider?
### What a Strong Answer Covers
- Settled scope and rough capacity estimates
- A data model for books and editions, inventory per location, carts, orders and payments
- Browse and search paths: a search index kept in sync with the catalog, caching, and a CDN for images
- Checkout: stock reservation, idempotent payment, and an order state machine with compensation on failure
- Strong consistency where it matters (stock, orders, payments) and eventual consistency elsewhere
- Scaling for peaks, failure handling and monitoring
### Follow-up Questions
- A highly anticipated release opens for pre-order and traffic spikes far above normal. What breaks first, and how do you protect checkout?
- How do you keep search results consistent with price and stock changes?
- E-books are added. What changes in inventory and fulfilment?
- The payment succeeds but the order service times out before recording it. What does the customer see, and how is it resolved?
Overview: A system design question: design an online bookstore with a searchable catalog, inventory, carts, orders and payments. It tests scoping an underspecified prompt, stock reservation when buyers race for the last copy, idempotent checkout and payment, search index freshness, caching and failure handling.