Skip to content

Design_amazon

Building the World’s Largest E-commerce Platform

Section titled “Building the World’s Largest E-commerce Platform”

Amazon.com revolutionized e-commerce and became the foundation for modern cloud computing through AWS.

Amazon by the Numbers
====================
┌─────────────────────────────────────────────────────────────┐
│ 300M+ active customer accounts │
│ 12M+ products (marketplace + own) │
│ 2B+ items sold annually │
│ $600B+ in annual revenue │
│ 175 fulfillment centers globally │
│ 1M+ items shipped per day at peak │
└─────────────────────────────────────────────────────────────┘
RequirementScaleTechnical Challenge
Product catalog12M+ itemsFast search, inventory
TransactionsMillions/hourACID at scale
RecommendationsReal-timeML at scale
Availability99.99%Global redundancy
SearchSub-100msFull-text search

Amazon Architecture
=================
┌─────────────────────────────────────────────────────────────┐
│ Users │
│ (Web, Mobile, Alexa, API) │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ CloudFront CDN │
│ (Edge locations globally) │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ API Gateway │
│ (Authentication, Routing) │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Service Layer │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Catalog │ │ Search │ │Pricing │ │Inventory│ │
│ │ Service │ │ Service │ │ Service │ │ Service │ │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Order │ │Payment │ │ User │ │Shipping │ │
│ │ Service │ │ Service │ │ Service │ │ Service │ │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Review │ │ Recc │ │ Cart │ │
│ │ Service │ │ Service │ │ Service │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Data Layer │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ DynamoDB │ │ Aurora │ │ ElastiCache│ │
│ │(Product)│ │ (Orders) │ │ (Redis) │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ S3 │ │ Elasticsearch│ │Redshift │ │
│ │(Images) │ │(Search) │ │(Analytics)│ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘

Amazon pioneered microservices, learning from early monolithic architecture challenges.

Evolution: Monolith → SOA → Microservices
=========================================
EARLY AMAZON (Monolith):
─────────────────────────
┌─────────────────────────────────┐
│ Amazon.com │
│ │
│ • All code in one repository │
│ • One massive Oracle database │
│ • 10,000+ developers │
│ • Deploy takes 8+ hours │
│ • Any change = risk │
└─────────────────────────────────┘
SERVICE-ORIENTED ARCHITECTURE (SOA):
─────────────────────────────────────
┌─────────┐ ┌─────────┐ ┌─────────┐
│Catalog │ │ Order │ │ User │
│ Service │ │ Service │ │ Service │
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
┌────┴───────────┴───────────┴────┐
│ Shared Infrastructure │
│ • Service communication │
│ • Data access patterns │
│ • Monitoring │
└─────────────────────────────────┘
TODAYS MICROSERVICES:
─────────────────────
┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
│SVC│ │SVC│ │SVC│ │SVC│ │SVC│ │SVC│ │SVC│
│ 1 │ │ 2 │ │ 3 │ │ 4 │ │ 5 │ │ 6 │ │ 7 │
└───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘
Each service:
• Owns its data
• Independent deploy
• Own team
• Own database

Amazon's Polyglot Persistence
============================
┌─────────────────────────────────────────────────────────────┐
│ DynamoDB │
│ ─────────────────────────────────────────────────────────│
│ │
│ Use: Product catalog, inventory, session cache │
│ │
│ Why: │
│ • Single-digit millisecond latency │
│ • Infinite scaling │
│ • Fully managed │
│ • Built by Amazon, optimized for their use │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Amazon Aurora │
│ ─────────────────────────────────────────────────────────│
│ │
│ Use: Orders, transactions, financial data │
│ │
│ Why: │
│ • MySQL/PostgreSQL compatible │
│ • 5x throughput of standard MySQL │
│ • Multi-AZ durability │
│ • ACID compliance │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Amazon Redshift │
│ ─────────────────────────────────────────────────────────│
│ │
│ Use: Analytics, data warehousing │
│ │
│ Why: │
│ • Petabyte scale │
│ • Columnar storage │
│ • SQL interface │
└─────────────────────────────────────────────────────────────┘

Order Processing Flow
===================
┌─────────────────────────────────────────────────────────────┐
│ Step 1: Add to Cart │
│ ─────────────────────────────────────────────────────────│
│ │
│ User → Cart Service → Validate → Store in DynamoDB │
│ │
│ (Cart persisted for 30 days) │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Step 2: Checkout │
│ ─────────────────────────────────────────────────────────│
│ │
│ • Retrieve cart items │
│ • Calculate pricing │
│ • Apply promotions │
│ • Calculate shipping │
│ • Validate inventory │
│ │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Step 3: Place Order │
│ ─────────────────────────────────────────────────────────│
│ │
│ • Create order in Aurora (transactional) │
│ • Reserve inventory │
│ • Initiate payment │
│ • Send to fulfillment │
│ │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Step 4: Payment Processing │
│ ─────────────────────────────────────────────────────────│
│ │
│ • Process payment (3D Secure) │
│ • Handle fraud detection │
│ • Confirm or decline │
│ • Update order status │
│ │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Step 5: Fulfillment │
│ ─────────────────────────────────────────────────────────│
│ │
│ • Route to fulfillment center │
│ • Pick and pack │
│ • Ship to customer │
│ • Track shipment │
│ │
└─────────────────────────────────────────────────────────────┘

AWS was born from Amazon’s internal infrastructure needs.

AWS: From Internal Tool to Cloud Platform
=========================================
2002: Amazon starts exposing internal services
2006: AWS launched with S3 and EC2
2007: AWS reaches 180,000 developers
2012: AWS generates $2B revenue
2023: AWS is $90B+ business
─────────────────────────────────────────
Internal → External Services:
Internal Need → AWS Service
───────────────── ──────────────
Compute for website → EC2
Store product images → S3
Search products → CloudSearch
Customer data → DynamoDB
Payment processing → Payment Services
Amazon's Recommendation System
============================
How it works:
──────────────
1. COLLABORATIVE FILTERING
"Users who bought X also bought Y"
• Based on purchase history
• Similar user behavior
2. CONTENT-BASED
"Because you browsed X"
• Product attributes
• Category preferences
3. PERSONALIZED
"Recommended for you"
• Your specific history
• Real-time context
─────────────────────────────────────────
Data Collection:
───────────────
• Every click tracked
• Every purchase recorded
• Every search stored
• Time on page
• Cart additions
• Reviews written

Amazon Engineering Principles
===========================
1. PIONEERED SOA
───────────────
• First major company to adopt
• Led to AWS
• Every team owns their service
2. DATA-DRIVEN
────────────
• Every decision backed by data
• A/B testing everything
• Metrics-first culture
3. CUSTOMER OBSESSION
─────────────────
• Start with customer, work backward
• "Most backward" approach
• Customer complaints → features
4. INVENTORY-VENDOR ISOLATION
──────────────────────────
• Independent services
• Fail independently
• Scale independently
5. PIONEERED CLOUD
───────────────
• AWS started internal
• Became external product
• Changed entire industry

  1. Service-oriented architecture - Pioneer of microservices
  2. AWS - Born from internal needs
  3. Polyglot persistence - Different databases for different needs
  4. DynamoDB - Fast, scalable NoSQL
  5. Order processing - Complex multi-step workflow
  6. Recommendations - ML-driven personalization

Next: Chapter 50: Designing Spotify