KatInterview

Design an E-Commerce Search and Typeahead System

System DesignModel answer
MediumModel answerSystem Designsystem-designautocompletesearch

Last updated

Architect a low-latency prefix typeahead and full-catalog product search system capable of handling high traffic spikes and near real-time inventory updates.

Scenario

Design the search subsystem for a global e-commerce platform. The system powers two core features in the user search flow:

  1. Prefix Autocomplete: As users type into the input field, the interface displays matching query terms and product categories in under 30 milliseconds.
  2. Product Catalog Search: When a user submits a query, the platform presents ranked product listings with multi-attribute filtering (such as price, condition, category, and delivery options), dynamic facets, sorting, and pagination.

System Requirements

Functional Scope

  • Provide the top 5 to 10 matching query terms and category links as the user types (prefix matching).
  • Perform full-text search over product titles, descriptions, and metadata.
  • Support faceted search, multi-field filtering, custom sorting (e.g., price, relevance, creation date), and pagination.
  • Ensure prompt reflection of catalog updates (out-of-stock items, price drops, or newly created listings).
  • Utilize user interactions (click-through rates, searches, conversion rates) to continuously update suggestion rankings and search relevance.

Constraints & Operational Targets

  • Catalog Volume: 500 million active inventory items.
  • Traffic Volume: 20,000 requests per second (RPS) average for full search (peaking at 60,000 RPS). Autocomplete traffic peaks at 100,000 RPS at the origin prior to edge throttling/caching.
  • Latency Budgets:
    • Autocomplete p99 < 30 ms.
    • Catalog Search p99 < 150 ms.
  • Availability Target: 99.99% availability.

Evaluation Criteria

Your design should cover:

  1. Data Ingestion & Invalidation: How changes in inventory status flow into search indices and autocomplete dictionaries.
  2. Dual Execution Paths: Trade-offs between dedicated custom trie engines versus off-the-shelf distributed search indices (e.g., OpenSearch / Elasticsearch completion engines) for typeahead.
  3. Caching Strategy: Multi-tiered caching layer across client, CDN, and backend caches to offload high-volume keystroke operations.
  4. Pagination Mechanics: Efficient mechanisms for deep pagination and handling transient listing updates during user sessions.
  5. Relevance & Content Moderation: Filtering zero-result queries, suppressing offensive or forbidden terms, and evaluating ranking performance.

Hints

Hint 1

Decouple the typeahead latency path from the heavy catalog search path, as their SLA, memory profiles, and query models differ significantly.

Hint 2

Estimate the size of the curated autocomplete dictionary; you may find it fits entirely inside RAM, which simplifies horizontal scaling via full replication.

Hint 3

Avoid offset-based deep pagination (e.g., OFFSET 10000) on distributed search engines; use cursor-based pagination with a point-in-time snapshot instead.