API Documentation Overview
Comprehensive documentation for the E-Commerce Microservices API. This RESTful API provides endpoints for user management, product catalog, orders, and payments with built-in caching and rate limiting.

Base URL

https://api.example.com/v1

Rate Limit

1000 requests/hour
Authentication
The API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header for all protected endpoints.

Login Endpoint

POST/auth/login
{
  "email": "user@example.com",
  "password": "securePassword123"
}

Using the Token

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
API Endpoints
Complete list of available endpoints with request/response examples and error handling.

Users

GET/users/:idProtected

Retrieve user information by ID. Returns user profile with associated metadata.

{
  "success": true,
  "data": {
    "id": "usr_123",
    "email": "user@example.com",
    "name": "John Doe",
    "role": "customer",
    "createdAt": "2024-01-15T10:30:00Z",
    "lastLogin": "2024-10-26T08:15:00Z"
  }
}
PUT/users/:idProtected

Update user profile information. Supports partial updates.

{
  "name": "John Smith",
  "phone": "+1234567890"
}

Products

GET/productsPublic

List all products with pagination, filtering, and sorting. Cached for 5 minutes.

Query Parameters
page: number (default: 1)
limit: number (default: 20, max: 100)
category: string
sort: price_asc | price_desc | name | newest
{
  "success": true,
  "data": [
    {
      "id": "prod_456",
      "name": "Premium Headphones",
      "description": "High-quality wireless headphones",
      "price": 299.99,
      "currency": "USD",
      "category": "electronics",
      "stock": 150,
      "images": ["https://cdn.example.com/img1.jpg"]
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 245,
    "pages": 13
  }
}
POST/productsAdmin Only

Create a new product. Requires admin authentication.

{
  "name": "Wireless Mouse",
  "description": "Ergonomic wireless mouse",
  "price": 49.99,
  "category": "electronics",
  "stock": 200,
  "images": ["https://cdn.example.com/mouse.jpg"]
}

Orders

POST/ordersProtected

Create a new order. Validates stock availability and processes payment.

{
  "items": [
    {
      "productId": "prod_456",
      "quantity": 2
    }
  ],
  "shippingAddress": {
    "street": "123 Main St",
    "city": "San Francisco",
    "state": "CA",
    "zip": "94102",
    "country": "US"
  },
  "paymentMethod": "card"
}
Database Schema
PostgreSQL database schema with Redis caching layer for optimal performance.

Users Table

CREATE TABLE users (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  email VARCHAR(255) UNIQUE NOT NULL,
  password_hash VARCHAR(255) NOT NULL,
  name VARCHAR(255) NOT NULL,
  role VARCHAR(50) DEFAULT 'customer',
  created_at TIMESTAMP DEFAULT NOW(),
  updated_at TIMESTAMP DEFAULT NOW(),
  last_login TIMESTAMP
);

CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_role ON users(role);

Products Table

CREATE TABLE products (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name VARCHAR(255) NOT NULL,
  slug VARCHAR(255) UNIQUE NOT NULL,
  description TEXT,
  price DECIMAL(10, 2) NOT NULL,
  category VARCHAR(100),
  stock INTEGER DEFAULT 0,
  images JSONB,
  created_at TIMESTAMP DEFAULT NOW(),
  updated_at TIMESTAMP DEFAULT NOW()
);

CREATE INDEX idx_products_category ON products(category);
CREATE INDEX idx_products_slug ON products(slug);

Redis Caching Strategy

products:list:* - Product listings (TTL: 5 minutes)
product:* - Individual products (TTL: 10 minutes)
user:session:* - User sessions (TTL: 24 hours)
rate_limit:* - Rate limiting counters (TTL: 1 hour)
Performance Optimization
Strategies and metrics for maintaining high performance under load.

Response Times

P50: 45ms
P95: 120ms
P99: 250ms

Throughput

Peak: 10,000 req/min
Average: 3,500 req/min
Uptime: 99.9%

Optimization Techniques

  • Redis caching for frequently accessed data with intelligent TTL management
  • Database connection pooling with automatic scaling based on load
  • Horizontal scaling with Kubernetes auto-scaling (2-10 pods)
  • CDN integration for static assets and image optimization
  • Async processing for heavy operations using Bull queue
Deployment & Infrastructure
Production deployment configuration with Docker and Kubernetes.

Docker Configuration

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/server.js"]

Kubernetes Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
      - name: api
        image: your-registry/api:latest
        ports:
        - containerPort: 3000
        env:
        - name: NODE_ENV
          value: "production"
        - name: REDIS_URL
          valueFrom:
            secretKeyRef:
              name: api-secrets
              key: redis-url
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 10

CI/CD Pipeline

name: Deploy to Production

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Run Tests
        run: npm test
      
      - name: Build Docker Image
        run: docker build -t api:undefined .
      
      - name: Push to Registry
        run: docker push api:undefined
      
      - name: Deploy to Kubernetes
        run: kubectl set image deployment/api api=api:undefined