# Real-World Deployment Scenario

Complete end-to-end deployment with all components.

## Scenario: E-commerce Platform

Deploy a scalable e-commerce platform across multiple regions.

### Architecture

```text
┌─────────────────────────────────────┐
│  Global Load Balancer (Route53)     │
│  (AWS US-East, UpCloud US-West)     │
└────────┬────────────────┬───────────┘
         │                │
    ┌────▼─────┐    ┌────▼─────┐
    │  AWS     │    │ UpCloud  │
    │ Region   │    │ Region   │
    │ US-East  │    │ US-West  │
    └────┬─────┘    └────┬─────┘
         │                │
    ┌────▼──────────────────────┐
    │ Primary DB  │ Read Replica │
    │ (PostgreSQL) (PostgreSQL)  │
    └───────────────────────────┘
```

### Complete Configuration

```nickel
{
  workspace = "ecommerce-production",

  # Global routing
  global_load_balancer = {
    name = "ecommerce-global",
    routing_policy = "geolocation",

    regions = [
      {
        name = "us-east",
        provider = "aws",
        region = "us-east-1",
        weight = 60
      },
      {
        name = "us-west",
        provider = "upcloud",
        zone = "us-sjc",
        weight = 40
      }
    ]
  },

  # Primary region (AWS)
  aws = {
    region = "us-east-1",

    vpc = {
      cidr_block = "10.0.0.0/16",
      enable_dns_hostnames = true
    },

    # Web tier
    web_tier = {
      asg = {
        min_size = 3,
        max_size = 20,
        desired_capacity = 5,
        instance_type = "t3.large",
        availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
      }
    },

    # API tier
    api_tier = {
      asg = {
        min_size = 3,
        max_size = 15,
        desired_capacity = 5,
        instance_type = "c5.xlarge",
        availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
      }
    },

    # Caching layer
    cache = {
      engine = "redis",
      num_cache_clusters = 3,
      node_type = "cache.r6g.xlarge",
      automatic_failover = true
    },

    # Storage
    s3 = {
      bucket = "ecommerce-assets",
      versioning = true,
      lifecycle_rules = [
        {
          days = 90,
          action = "transition",
          storage_class = "GLACIER"
        }
      ]
    }
  },

  # Secondary region (UpCloud)
  upcloud = {
    zone = "us-sjc",

    servers = [
      {
        hostname = "web-01.us-west",
        plan = "4xCPU-8GB",
        count = 2
      },
      {
        hostname = "api-01.us-west",
        plan = "8xCPU-16GB",
        count = 2
      }
    ]
  },

  # Primary database (AWS RDS)
  database = {
    primary = {
      provider = "aws",
      engine = "postgres",
      version = "15",
      instance_class = "db.r6i.2xlarge",
      allocated_storage = 500,
      multi_az = true,
      backup_retention_period = 30
    },

    # Read replica in secondary region
    replica = {
      provider = "upcloud",
      type = "read-replica",
      source = "primary"
    }
  },

  # Monitoring
  monitoring = {
    prometheus = {
      enabled = true,
      retention = "30d"
    },
    grafana = {
      enabled = true,
      dashboards = ["web-metrics", "api-metrics", "db-metrics"]
    },
    alerting = {
      enabled = true,
      rules = [
        { alert = "HighCPU", threshold = 80 },
        { alert = "HighMemory", threshold = 85 },
        { alert = "HighDiskUsage", threshold = 90 }
      ]
    }
  },

  # Logging
  logging = {
    elasticsearch = {
      enabled = true,
      retention = "30d"
    },
    kibana = {
      enabled = true
    }
  },

  # Security
  security = {
    tls = {
      enabled = true,
      version = "1.3"
    },
    waf = {
      enabled = true,
      rules = ["owasp-crs"]
    },
    vault = {
      enabled = true,
      backend = "secretumvault"
    }
  }
}
```

### Deployment Process

```bash
#!/usr/bin/env nu

def deploy-ecommerce [] {
  print "Deploying ecommerce platform..."

  # Workspace setup
  provisioning workspace create ecommerce-production
  provisioning workspace use ecommerce-production

  # Store credentials
  provisioning vault add aws-access-key $AWS_KEY
  provisioning vault add aws-secret-key $AWS_SECRET
  provisioning vault add db-password $DB_PASSWORD

  # Deploy configuration
  provisioning infra apply --config ecommerce-config.ncl

  # Verify deployment
  sleep 60sec
  provisioning test smoke-tests
  provisioning test integration-tests

  # Setup monitoring
  provisioning monitoring setup

  # Complete
  print "✓ Ecommerce platform deployed successfully"
}

deploy-ecommerce
```

## Related Documentation

- [Multi-Cloud Examples](./multi-cloud.md)
- [High Availability](./high-availability-examples.md)
- [Production Readiness](../guides/production-readiness.md)
