Design Principles for E-commerce Websites

Sep 4, 2024

Lecture Notes: Designing E-commerce Websites like Amazon

Introduction

  • Discussion on designing an e-commerce website like Amazon.
  • Similar principles apply to other e-commerce platforms like eBay, Walmart, Flipkart.
  • Outline of the lecture:
    • Functional and non-functional requirements
    • Capacity estimations
    • Database design
    • APIs
    • System design for scalability
    • Assumptions in design process

Functional Requirements

  • Focus on core functionalities due to time constraints (1-hour system design interview).
  • Key functionalities include:
    • Product search
    • Product recommendations on homepage
    • Order placement and status viewing
    • Product reviews
  • Assumptions: User profile creation, product onboarding, payment gateway available.

Non-Functional Requirements

  • Low latency for recommendation and search services.
  • High consistency required for order placement, payment, and status viewing.

Capacity Estimations

  • User Base: 300 million monthly active users.
  • Search Estimations:
    • 10 searches per user per month.
    • Total: 3 billion searches/month.
    • Translates to approximately 1,000 searches per second.
  • Storage Estimations:
    • 10 million products needing 10 MB each.
    • Total: 100 terabytes of storage for product information.

Database Design

  • User Database: SQL database with structured information (user ID, name, login timestamps, addresses).
  • Address Database: Separate SQL database to handle multiple addresses per user.
  • Product Database: NoSQL (DynamoDB/MongoDB) due to unstructured data.
  • Order Database: NoSQL for flexible storage of varied order items.
  • Review Database: NoSQL key-value store with product ID as key.

APIs

  • GetRecommendationService: User ID input, returns product recommendations.
  • SearchService: Search string and user ID, outputs deliverable products.
  • AddToCartService: Inputs include user ID, product ID, quantity; outputs success status.
  • PlaceOrderService: Takes user ID, order details, returns success status if inventory available.
  • CheckOrderStatusService: Takes order ID, returns order status.

High-Level System Design

  • Functional requirements include search service, add to cart, place order, and review services.
  • Recommendation Generation: Based on search history, stored in a separate database.
  • Order Processing: Sequential flow from cart to order database.
  • Review Interaction: Triggered through recommendations and search.

Scaling the System

  • Load Balancer: Distributes load; includes standby for redundancy.
  • Multiple Instances: For each service to enhance failure resilience.
  • Elasticsearch: Enhances search performance for millions of users.
  • Master-Slave Database Design: For read-heavy product database.
  • Data Redundancy: Multiple copies for reliability in all databases.
  • Archiving: Older data like search history and past orders to maintain performance.
  • Caching: For immediate access to recommendations and frequent queries.
  • Message Queues: Added between services to decouple and reduce dependencies.

Conclusion

  • End of lecture on scalable e-commerce system design.
  • Encouragement to engage with related content for deeper understanding.