Skip to content

e-Commerce System Design

1. Business Requirements

Functional Requirements

  • User registration and authentication (customers, admins, vendors)
  • Product catalog management (add, update, remove products)
  • Product search, filtering, and recommendations
  • Shopping cart and checkout process
  • Order management (create, update, cancel, track orders)
  • Payment processing (integration with payment gateways)
  • Inventory management and stock alerts
  • Generate alerts (low stock, order status, promotions)
  • Mobile-ready responsive UI
  • Reviews and ratings for products
  • Notifications (email/SMS/push for order status, promotions)
  • Analytics and trends (sales, popular products, customer behavior)

Non-Functional Requirements

  • 99.9% availability (max ~8.76 hours downtime/year)
  • Scalability to handle high traffic and flash sales
  • Secure data storage and access control (PCI DSS for payments)
  • Fast response times (<300ms for most requests)
  • Audit logging and monitoring
  • Backup and disaster recovery
  • GDPR/data privacy compliance
  • Mobile responsiveness

Out of Scope

  • In-person POS integration
  • Marketplace for third-party sellers (if not a core requirement)
  • Logistics/fleet management
  • Loyalty/rewards program (unless specified)

2. Estimation & Back-of-the-Envelope Calculations

  • Users: 500,000 customers, 100 admins/vendors
  • Products: 100,000
  • Daily transactions: ~100,000 (browsing, cart, orders, payments)
  • Peak concurrent users: ~10,000
  • Data size:
    • Product catalog: 100,000 × 2 KB ≈ 200 MB
    • User data: 500,100 × 2 KB ≈ 1 GB
    • Orders: 10M × 1 KB ≈ 10 GB
    • Reviews: 2M × 0.5 KB ≈ 1 GB
    • Inventory: 100,000 × 0.5 KB ≈ 50 MB
    • Total DB size: ~12 GB (excluding logs, backups, images)
    • Product images: 100,000 × 200 KB ≈ 20 GB (stored in object storage)
  • Availability:
    • 99.9% = 8.76 hours/year downtime max
    • Use managed DB, multi-AZ deployment, health checks, auto-scaling

3. High Level Design (Mermaid Diagrams)

Component Diagram

mermaid
flowchart LR
  User[User (Web/Mobile)]
  LB[Load Balancer]
  App[Application Server]
  DB[(Database)]
  Cache[Cache (Redis)]
  Storage[Object Storage (Images)]
  Payment[Payment Gateway]
  Analytics[Analytics Engine]
  Alert[Alert/Notification Service]

  User --> LB --> App
  App --> DB
  App --> Cache
  App --> Storage
  App --> Payment
  App --> Alert
  App --> Analytics
  Analytics --> DB

Data Flow Diagram

mermaid
sequenceDiagram
  participant U as User
  participant A as App Server
  participant D as Database
  participant C as Cache
  participant S as Storage
  participant P as Payment
  participant L as Alert Service

  U->>A: Place Order
  A->>C: Check Product Availability
  C-->>A: Hit/Miss
  A->>D: Create Order Record
  D-->>A: Success/Fail
  A->>P: Process Payment
  P-->>A: Payment Status
  A->>S: Update Inventory
  S-->>A: Success/Fail
  A->>L: Send Order Confirmation
  A-->>U: Response

Key Design Decisions

  • Database: Relational DB (e.g., PostgreSQL) for transactional data, strong consistency
  • Cache: Redis for fast lookups (product catalog, sessions, inventory)
  • Object Storage: For product images and attachments (e.g., AWS S3, Azure Blob)
  • Analytics: Batch or streaming (e.g., Kafka + Spark, or managed cloud analytics)
  • Deployment: Cloud-based, multi-AZ, managed services for high availability
  • Alerting/Notifications: Email/SMS/push via third-party service (e.g., Twilio, Firebase)
  • Payment: Integration with secure payment gateways (Stripe, PayPal, etc.)

4. Conceptual Design

Entities

  • User: id, name, email, password_hash, role, address, registration_date, status
  • Product: id, name, description, price, category, image_url, stock, status
  • Order: id, user_id, order_date, status, total_amount, payment_id, shipping_address
  • OrderItem: id, order_id, product_id, quantity, price
  • Review: id, user_id, product_id, rating, comment, created_at
  • Inventory: id, product_id, quantity, last_updated
  • Alert: id, user_id, type (order/stock/promo), message, created_at, status
  • Payment: id, order_id, amount, status, payment_method, transaction_id

Key Flows

  • Order Placement:
    1. User places order
    2. App checks cache for product availability, falls back to DB
    3. Creates Order and OrderItem records
    4. Processes payment via gateway
    5. Updates inventory
    6. Sends order confirmation alert
  • Inventory Alerts:
    • System monitors inventory and triggers alerts for low stock
  • Analytics:
    • Periodic jobs aggregate sales, trends, and customer behavior

Security

  • Role-based access control (RBAC)
  • Input validation, rate limiting
  • Encrypted connections (HTTPS)
  • PCI DSS compliance for payments
  • Regular backups and audit logs

5. Bottlenecks and Refinement

Potential Bottlenecks

  • Database contention (high read/write during sales):
    • Use read replicas, caching, and DB connection pooling
  • Payment processing:
    • Use async queues and retries for payment gateway integration
  • Image storage/delivery:
    • Use scalable object storage and CDN for images
  • Analytics workload:
    • Offload to separate analytics engine, run during off-peak
  • Alert delivery:
    • Use async queues for notifications
  • Single region failure:
    • Deploy across multiple availability zones/regions

Refinement

  • Monitor system metrics and auto-scale app servers
  • Regularly test failover and backup restores
  • Optimize queries and indexes for frequent operations
  • Consider sharding if user/product/order volume grows significantly

This design provides a scalable, highly available, and mobile-ready e-commerce system with robust alerts, analytics, and operational best practices.