KatInterview

Multi-Vendor Order Fulfillment System

System DesignModel answer
MediumModel answerSystem Designdistributed-systemssaga-patternidempotency

Last updated

Design a service that queries multiple vendor APIs concurrently, selects the best offer within constraints, and coordinates payment with order placement.

You're building a service that helps customers find and complete purchases across multiple third-party vendors. When a customer wants to buy a product, your system checks which vendors have it in stock, compares prices, and completes the transaction with the vendor offering the best deal.

Your Task

Design an order fulfillment broker that:

  1. Queries multiple vendors concurrently to find availability and pricing for a requested product
  2. Selects and purchases from the optimal vendor based on price constraints and a time window
  3. Coordinates payment authorization and capture to ensure money moves only when the vendor confirms the order
  4. Handles failures gracefully: network timeouts, vendor outages, partial responses, and ambiguous states

Functional Scope

Your API should accept:

  • Product identifier, quantity, maximum acceptable price per unit, and request timeout
  • Return an order identifier immediately and process asynchronously

Your system must:

  • Support status queries for in-flight orders
  • Prevent duplicate purchases if a vendor request times out and retries
  • Maintain an audit trail of vendor responses and state transitions

Constraints

  • 10–15 vendor integrations, each with different response times and reliability
  • Peak load: hundreds of purchase requests per second
  • Timeout window: 5 seconds to 5 minutes
  • A purchase at one vendor must never result in charging the customer twice or buying from two vendors

What to Cover

  • API contracts and workflow orchestration
  • State management and transitions
  • How you ensure exactly-once purchase semantics
  • Database schema and storage strategy
  • Failure modes and recovery mechanisms

Hints

Hint 1

Think about the difference between attempting a vendor API call and knowing its outcome—timeouts create ambiguity

Hint 2

Payment authorization before purchase and capture after confirmation creates a two-phase commit across systems

Hint 3

An outbox pattern ensures state changes and their side effects (notifications, vendor calls) stay consistent