Design a Product Search & Ranking System
A Staff-level walkthrough of an e-commerce product search system that ranks 600M+ listings under a 200ms budget — trading recall against precision through a two-stage retrieval-and-ranking funnel, then blending organic results with sponsored placements. It weighs multi-objective scoring across relevance, purchase likelihood, and business value, near-real-time index freshness, and a cross-team ranking-model migration. Follow it top to bottom, or jump to any step.
Scope & ambiguity
Framing statement:
“Before I dive in, let me frame how I’d approach this. Amazon’s product search spans multiple organizations — a search infrastructure team owning the index, a ranking/ML team owning relevance, an ads team owning sponsored placements, a catalog team owning product data, and a frontend team owning the search experience. The key architectural challenge is building a multi-objective ranking system that balances relevance, purchase likelihood, and monetization — all within a 200ms latency budget across 600M+ products and billions of daily queries. I’ll focus on the indexing pipeline, query understanding, ranking model (A9/A10), and sponsored product integration, and propose a phased approach.”
Phased delivery:
Team ownership:
Key ambiguity I’d challenge:
“When we say ’relevance,’ I want to clarify the optimization target: are we maximizing click-through rate, add-to-cart rate, or purchase conversion rate? The ranking model architecture changes significantly — CTR optimization favors attractive listings, while purchase-conversion optimization favors products with competitive pricing and good reviews. At Amazon’s scale, a 0.1% improvement in search-to-purchase conversion represents hundreds of millions in annual revenue.”
Requirements
Functional Requirements (Phase 1-2)
- FR1: Users can search the product catalog by keywords, returning ranked results within a latency budget
- FR2: Results are ranked by a multi-objective function combining relevance, purchase likelihood, and business value
- FR3: Search supports filtering by category, price range, brand, ratings, Prime eligibility, and other facets
- FR4: New/updated products (price, stock, new listings) are searchable within 5 minutes
- FR5: Sponsored products appear within organic results, subject to relevance constraints
- FR6: Search is personalized based on user history, location, and Prime membership status
Non-Functional Requirements
Organizational Context
- Existing system: A9/A10 search engine is mature — this is an evolution, not greenfield. The A10 generation added emphasis on organic engagement, external traffic signals, and seller authority over pure sales velocity.
- Regulatory: GDPR (EU), CCPA (California), data residency requirements for marketplace-specific data, FTC advertising disclosure rules for sponsored results.
- Infrastructure: Built on AWS — DynamoDB (151M req/sec peak on Prime Day 2025), SQS (166M msg/sec peak), Aurora, OpenSearch, SageMaker for ML inference, Kinesis for streaming.
- Timeline: Phase 1 in 3 months with Search Infrastructure + Ranking teams (12-15 engineers).
Out of Scope (Explicitly)
- Alexa voice search interface (Phase 3)
- Visual search / search-by-image (Phase 3)
- Rufus conversational AI search (Phase 3)
- Seller-facing search analytics dashboard
- Amazon Fresh / Whole Foods specialized search
Back-of-envelope estimation
Scale Numbers
Storage Estimation
Cost Estimation
Architectural implication: ML inference for ranking is the dominant cost — each query invokes the ranking model on 1000+ candidates. We need a two-stage retrieval/ranking architecture to limit the number of candidates scored by the expensive neural model. Batch inference and model distillation (teacher → student) are critical cost levers.
API design
External API (Client-Facing)
Inter-Service Contracts
API Governance
- Versioning: URI versioning for external (/v1/), header versioning for internal gRPC services
- Schema registry: Protobuf for all inter-service and event schemas, enforced via CI/CD pipeline
- Rate limiting: Per-user: 100 searches/min, per-IP: 500/min (bot protection), per-seller-API: 1000/min
- Deprecation policy: Minimum 6-month sunset window for external API versions; internal services require 3-month migration window
Data model
Core Entities
Data Ownership Boundaries
Storage Technology Choices
Data Lifecycle
High-level architecture
Architecture Diagram
Service Boundaries with Ownership
Sync vs Async Communication
Failure Domain Boundaries
Deep dives
WHERE STAFF IS WONCore Decision: Two-Stage Retrieval + Ranking
This is the most consequential architectural decision for search at Amazon’s scale. Scoring all 600M products per query is impossible within 200ms. We need a funnel architecture.
Why two-stage over single-stage: A single neural model scoring 600M products at ~0.1ms each would take 60,000 seconds. Two-stage reduces this to BM25 over the inverted index (O(query_terms) with posting list intersection) plus neural scoring of 1,000 candidates (~50ms on GPU). This is the standard approach used by Amazon, Google, and all large-scale search systems.
Query Understanding Pipeline
Indexing Pipeline
Ranking Model (A9/A10)
Sponsored Products Integration
Autocomplete and Query Suggestion
Multi-team rollout
Migration Strategy: A9 → A10 Ranking + Semantic Search
The system evolves from keyword-only BM25 search to a hybrid keyword + semantic retrieval with a more sophisticated A10 ranking model that incorporates external traffic and organic engagement signals.
Phase 1: Shadow Scoring (Weeks 1-6)
- Deploy new A10 ranking model alongside existing A9 model
- All queries scored by both models; A9 remains source of truth for production results
- Log A10 scores for offline comparison: measure NDCG@10, conversion prediction accuracy
- No user-facing impact; build confidence in A10 model quality
- Team: Ranking & Relevance (4 engineers)
Phase 2: Interleaved Experiment (Weeks 7-12)
- Run interleaved A/B test: for each query, randomly select half the result positions from A10, half from A9
- Measure per-position click-through rate and purchase conversion
- Simultaneously deploy semantic retrieval (k-NN) as an additional retrieval path in Stage 1
- Gate: A10 must show statistically significant improvement (p < 0.05) on purchase conversion
- Team: Ranking + Search Infrastructure (8 engineers)
Phase 3: Progressive Rollout (Weeks 13-20)
- 1% → 5% → 25% → 50% → 100% of traffic on A10 ranking
- Rollout by marketplace: start with amazon.com (US), then .co.uk, .de, .co.jp
- Monitor: conversion rate, revenue per search, customer complaints, seller escalations
- Each marketplace requires localized model fine-tuning (language, buying patterns)
- Team: All search teams (15+ engineers)
Phase 4: A9 Decommission (Weeks 21-28)
- Migrate remaining long-tail marketplaces to A10
- Decommission A9 scoring endpoints
- Archive A9 model artifacts and training pipelines
- Update on-call runbooks and dashboards
Rollback Plan
Bottlenecks & evolution
Bottleneck Analysis
Observability
Key metrics (RED method):
Critical alerts:
1. Zero-result rate > 5%: Indicates index corruption or query understanding regression — page the search on-call immediately
2. End-to-end p99 > 300ms: Ranking model degradation or OpenSearch overload — trigger auto-scaling and consider fallback to BM25-only ranking
3. Index freshness lag > 10 min: Kinesis pipeline stalled — check DLQ depth, consumer lag, and OpenSearch cluster health
4. Conversion rate drop > 2% (hourly): Ranking model regression — auto-rollback to previous model version via SageMaker endpoint rollback
5. Sponsored fill rate drop > 20%: Ad auction service degraded — alert ads on-call, organic search unaffected
Distributed tracing:
- Trace from client search request → API Gateway → Query Understanding → Search Retrieval (parallel: BM25 + k-NN) → Ranking Service → Sponsored Products → response assembly → client render
- Each span includes: service name, latency, cache hit/miss, number of candidates at each stage, model version used
- Correlation ID propagated through all services and Kinesis events for end-to-end debugging
- Sampled at 1% for normal traffic, 100% for error paths and latency outliers (p99+)
2-3 Year Evolution
Year 1: Foundation + A10 Migration
- A10 ranking model fully deployed across all 20+ marketplaces
- Semantic search (k-NN vector retrieval) live alongside BM25, improving recall for long-tail and misspelled queries
- Real-time index freshness < 1 minute for price/stock, < 5 minutes for new listings
- Personalization v1: basic user affinity signals (brand, category, price range) influencing ranking
- Operational maturity: comprehensive on-call runbooks, automated model rollback, Prime Day load testing playbook
- Cost optimization: model distillation (large teacher → small student GBDT) reduces GPU inference cost by 40%
Year 2: Intelligence + Multimodal
- Visual search: user uploads a photo → image embedding → k-NN retrieval against product image embeddings. Enables "find this product" from Instagram screenshots or real-world photos. Requires a new image embedding pipeline (SageMaker + S3).
- Conversational search via Rufus: natural language queries ("I need a birthday gift for a 10-year-old who likes space") → LLM generates structured search query + curated results. Architecturally, Rufus sits as a pre-processor before Query Understanding, translating conversational intent into structured search parameters.
- Cross-marketplace search: unified index enabling "search Amazon Japan from Amazon US" for cross-border shopping. Requires multilingual embeddings and currency/shipping cost integration.
- Advanced personalization: session-level intent modeling (user searched "tent" then "sleeping bag" → suggest "camping gear"), collaborative filtering signals from similar users.
Year 3: Platform + Anticipatory
- Search-as-a-platform: internal search API used by Alexa Shopping, Amazon Fresh, Whole Foods, Prime Video (product placement), and third-party sellers (search analytics API)
- Anticipatory search: predict what user will search based on context — time of year (sunscreen in June), recent purchases (bought printer → suggest ink), life events (baby registry → baby products). Pre-compute personalized search result pages for predicted queries and cache them.
- Real-time pricing integration: search results dynamically re-ranked as competitor prices change (web scraping pipeline → feature store → live ranking adjustment)
- Federated search: single query returns results across Amazon.com + Amazon Fresh + Whole Foods + third-party integrations, with unified ranking
Cost Optimization Roadmap
Summary
The key Principal SDE (L7) insights in this design:
1. Two-stage retrieval + ranking funnel is the core architectural pattern — BM25 + ANN retrieval (1000 candidates in 30ms) followed by neural ranking (50 results in 50ms), enabling 200ms end-to-end on 600M products
2. Multi-objective ranking balances relevance, purchase likelihood, and business value — the weight tuning between these objectives is the most commercially impactful decision at Amazon
3. A9 → A10 migration via shadow scoring, interleaved experiments, and progressive rollout with per-marketplace fine-tuning — a Principal SDE owns the cross-team migration plan
4. Team boundaries follow service boundaries (Conway’s Law): Query Understanding, Search Infrastructure, Ranking/ML, Sponsored Products, Catalog, and Search Experience teams each own their service and data
5. Failure domain isolation ensures ads failures don’t break organic search, ML failures fall back to BM25, and index pipeline lag doesn’t affect serving
6. Cost model identifies ML inference as the dominant cost and proposes distillation + caching as primary levers — Frugality LP in action
7. 3-year evolution from keyword search → semantic + personalized → conversational + anticipatory + platform, positioning search as Amazon’s core commerce engine
Rubric — Senior vs Staff
Want more breakdowns like this?
Join free early access for upcoming RAG, LLM eval, agents, and AI infrastructure walkthroughs.