KatInterview

Design a Multi-Vendor Book Aggregator & Automated Ordering Service

System DesignModel answer
MediumModel answerSystem Designsystem-designdistributed-systemsfault-tolerance

Last updated

Design an asynchronous system that aggregates quotes across hundreds of vendor APIs to find the best price for an ISBN, places an order within a target bid, and manages payment consistency.

You are tasked with designing the system backend for an automated book procurement platform.

When a user submits a search request containing an ISBN, a maximum bid price, and a payment token, the system must:

  1. Query hundreds of third-party vendor endpoints to retrieve current price quotes.
  2. Identify the vendor offering the lowest price.
  3. If the lowest price is less than or equal to the maximum bid price, immediately place the order and process payment.
  4. If the lowest price exceeds the maximum bid price, notify the user of the lowest price found.
  5. If no vendors have stock, inform the user that the item is currently out of stock.

Context & Constraints

  • Asynchronous & High Latency Vendors: Downstream vendors respond asynchronously (either via webhook callbacks or non-blocking polling/HTTP streaming), and their latencies vary wildly.
  • Scale: High query volume for popular titles.
  • Consistency: The system must guarantee that money is never captured without a confirmed vendor order, and books are never ordered without valid payment authorization.

Key Areas to Cover

  1. Core Architecture & Request Lifecycle: Define client APIs, background workers, event flows, state machine, and data models.
  2. Downstream Fault Tolerance & Partial Results: Describe timeout handling, circuit breakers, fan-out strategy, and how partial/incomplete quotes affect decision-making.
  3. Caching & Load Mitigation: Address request coalescing (thundering herd), caching strategies for price quotes, and safe TTL invalidation.
  4. Transaction Consistency & Idempotency: Detail the step-by-step workflow for charging the payment source and placing downstream vendor orders, including compensation logic for failure scenarios.

Hints

Hint 1

Use an explicit state machine for request lifecycles to handle asynchronous callbacks safely.

Hint 2

Separate payment authorization (hold) from payment capture to eliminate financial risks if downstream fulfillment fails.

Hint 3

Use single-flight request coalescing (e.g., Redis locks or Go singleflight) to prevent thundering herd calls on downstream vendors for popular ISBNs.