Katkat

Design an Online Book Seller Platform

DatabricksSoftware Engineer · Onsite

Last updated

Design an end-to-end e-commerce platform for selling books, balancing read-heavy catalog exploration with strictly consistent inventory reservation and fault-tolerant checkout workflows.

Scenario

Design an online bookstore where customers can discover books, check availability, place orders, complete payments, and monitor fulfillment status. The system must support high-volume browsing alongside transactional consistency for purchasing to prevent overselling.

Requirements

Functional Requirements

  1. Catalog Search & Browse: Users can search books by title, author, genre, or ISBN, and view details (pricing, ratings, stock status).
  2. Cart & Inventory Reservation: Users can add books to a cart and reserve inventory temporarily during checkout.
  3. Order Placement & Payment: Securely process payments via third-party gateways and generate confirmed orders.
  4. Order Lifecycle & Tracking: Track order transitions (Created, Paid, Fulfilling, Shipped, Delivered, Cancelled).

Non-Functional Requirements

  1. Consistency vs. Availability: High availability for catalog browsing and search; strong consistency for inventory reservation and payment processing.
  2. Low Latency: Catalog search under 100 ms (p95); checkout submission under 500 ms (p95).
  3. Resilience & Idempotency: Zero duplicate charges or orders due to network retries; graceful recovery from external payment provider outages.

Scale & Traffic Estimates

  • Catalog: 50 million unique book titles.
  • Users: 10 million daily active users (DAU).
  • Search Queries: Average 25,000 queries per second (QPS), peaking at 50,000 QPS.
  • Purchases: 500 orders per second average, peaking at 2,000 orders per second during book launches or holiday sales.

Key Areas to Cover

  1. API Design: Define core endpoints for search, checkout initiation, payment callback, and order status lookup.
  2. Data Modeling: Schema for books, inventory, shopping carts, and order state machines. Address relational vs. document/search store trade-offs.
  3. Inventory Management & Concurrency: How to reserve inventory during checkout without long-lived database locks or overselling.
  4. Order Processing Workflow: Architecture for orchestrating checkout, payment gateways, and order status transitions (e.g., Saga pattern vs. two-phase commits).
  5. Search Architecture: Mechanism to keep search indices updated with inventory and catalog changes.
  6. Observability & Fault Tolerance: Handling dead-letter queues, idempotent payment webhooks, and metric alerting for failed checkouts.

Hints

Hint 1

Separate read-heavy catalog search from write-heavy transactional order processing using a CQRS pattern with dedicated search engines like Elasticsearch.

Hint 2

Prevent overselling without blocking databases by implementing short-lived inventory reservations using atomic Redis operations or conditional database updates with TTLs.

Hint 3

Use an asynchronous saga or workflow engine (e.g., Temporal or Kafka-driven state machine) to coordinate payment and fulfillment, ensuring every checkout step is idempotent.

Follow-up questions

  • How would you handle a flash sale where 50,000 users attempt to buy the remaining 100 copies of an exclusive signed book at the same second?
  • If the third-party payment gateway charges the customer but network failure prevents your system from receiving the acknowledgment, how do you reconcile the state?
  • How would you design the search indexing pipeline to reflect price or stock changes within seconds without overwhelming the search cluster?