Design_amazon
Chapter 49: Designing Amazon
Section titled “Chapter 49: Designing Amazon”Building the World’s Largest E-commerce Platform
Section titled “Building the World’s Largest E-commerce Platform”49.1 Amazon Overview
Section titled “49.1 Amazon Overview”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 │ └─────────────────────────────────────────────────────────────┘Requirements Analysis
Section titled “Requirements Analysis”| Requirement | Scale | Technical Challenge |
|---|---|---|
| Product catalog | 12M+ items | Fast search, inventory |
| Transactions | Millions/hour | ACID at scale |
| Recommendations | Real-time | ML at scale |
| Availability | 99.99% | Global redundancy |
| Search | Sub-100ms | Full-text search |
49.2 High-Level Architecture
Section titled “49.2 High-Level Architecture” 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)│ │ │ └──────────┘ └──────────┘ └──────────┘ │ └─────────────────────────────────────────────────────────────┘49.3 Service-Oriented Architecture
Section titled “49.3 Service-Oriented Architecture”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 database49.4 Database Strategy
Section titled “49.4 Database Strategy”Choosing the Right Database
Section titled “Choosing the Right 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 │ └─────────────────────────────────────────────────────────────┘49.5 Order Processing Pipeline
Section titled “49.5 Order Processing Pipeline” 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 │ │ │ └─────────────────────────────────────────────────────────────┘49.6 Key Innovations
Section titled “49.6 Key Innovations”Amazon Web Services (AWS)
Section titled “Amazon Web Services (AWS)”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 ServicesRecommendation Engine
Section titled “Recommendation Engine” 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 written49.7 Key Learnings from Amazon
Section titled “49.7 Key Learnings from Amazon” 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 industrySummary
Section titled “Summary”- Service-oriented architecture - Pioneer of microservices
- AWS - Born from internal needs
- Polyglot persistence - Different databases for different needs
- DynamoDB - Fast, scalable NoSQL
- Order processing - Complex multi-step workflow
- Recommendations - ML-driven personalization