# Metis Multi-Region Deployment

This document describes the multi-region deployment strategy for Metis, the
TypeScript port of Minerva (multimedia lecture generation system), within the
Oshun monorepo infrastructure.

## Table of Contents

1. [Current Infrastructure from Minerva](#current-infrastructure-from-minerva)
2. [Metis in Oshun's ECS + RunPod Architecture](#metis-in-oshuns-ecs--runpod-architecture)
3. [Multi-Region Considerations](#multi-region-considerations)
4. [Recommended Deployment Topology](#recommended-deployment-topology)
5. [Database Replication Strategy](#database-replication-strategy)
6. [CDN and Edge Caching](#cdn-and-edge-caching)
7. [GPU Compute Distribution](#gpu-compute-distribution)
8. [Estimated Costs Per Region](#estimated-costs-per-region)

---

## Current Infrastructure from Minerva

Minerva's existing infrastructure is defined across three IaC systems, each
serving a different deployment context.

### AWS CDK Stacks (Primary)

Minerva uses a modular AWS CDK application with six stacks:

| Stack                   | Purpose                                                                          |
| ----------------------- | -------------------------------------------------------------------------------- |
| NetworkStack            | VPC, subnets (public/private/isolated), NAT gateways, VPC endpoints              |
| SecurityStack           | Secrets Manager, IAM roles (execution, API, worker, batch), AWS Config           |
| StorageStack            | S3 buckets (courses, media, exports, logs), ECR repositories, lifecycle policies |
| ObservabilityStack      | CloudWatch log groups, dashboards, alarms, SNS topics                            |
| RedisStack              | ElastiCache replication group (optional, enabled in staging/prod)                |
| ComputeStack            | ECS Fargate cluster, API/worker services, ALB, SQS queues, auto-scaling          |
| SchedulerStack          | EventBridge rules for batch processing and health checks                         |
| GlobalDistributionStack | Route53 latency/failover/weighted routing (when multi-region enabled)            |
| StorageReplicaStack     | Cross-region S3 replica buckets for disaster recovery                            |

### Pulumi Configuration (Alternative)

A parallel Pulumi Python program provisions networking, secrets, monitoring,
database (RDS PostgreSQL with read replicas), and RunPod endpoints. The
production Pulumi config specifies:

- 3 AZs in us-east-1
- `db.r6g.large` with 2 read replicas, Multi-AZ, 35-day backup retention
- RunPod with 1-10 workers on NVIDIA RTX A4000 GPUs

### Terraform Modules (Oshun Monorepo)

Phase 19 of the Oshun monorepo introduces a consolidated Terraform layer under
`infra/terraform/` with modules for ECS, ALB, VPC, ECR, SQS, S3, Secrets
Manager, SSM, CloudWatch, and per-domain ECS service definitions. This is the
target deployment platform for Metis.

### Docker Compose (Local Development)

Minerva's local stack includes Neo4j 5.13, MongoDB 7.0, Weaviate 1.23, and Redis
7.2. The Oshun monorepo provides PostgreSQL 16 (pgvector), Redis 7, MinIO,
Mailpit, and optional Elasticsearch, Qdrant, Kafka, Neo4j, and observability
services.

### Existing Multi-Region Support

Minerva's CDK config already has scaffolding for multi-region deployment:

- `multi_region` config block: primary/secondary regions, active-passive mode,
  per-region stack naming with suffix mode
- `global_distribution` config block: Route53 latency/failover/weighted routing,
  health checks
- `disaster_recovery` config block: S3 cross-region replication, secrets
  replication, RDS replication, RPO/RTO targets
- `StorageReplicaStack`: Creates replica S3 buckets in the DR region with
  replication policies
- `GlobalDistributionStack`: Creates Route53 records and health checks per
  region

Production DR targets: RPO 1 hour, RTO 4 hours, backup region us-west-2.

---

## Metis in Oshun's ECS + RunPod Architecture

Metis fits into the Phase 19 two-platform architecture as a domain alongside
Isis, Sophia, Hathor, Bellona, and others.

### Architecture Position

```
                    ┌─────────────────────────────┐
                    │     Route53 / CloudFront     │
                    │   (global traffic routing)   │
                    └──────────────┬───────────────┘
                                   │
                    ┌──────────────▼───────────────┐
                    │     ALB (per region)          │
                    │   /metis/* -> Metis TG        │
                    │   /isis/*  -> Isis TG         │
                    │   /sophia/* -> Sophia TG      │
                    └──────────────┬───────────────┘
                                   │
         ┌─────────────────────────┼─────────────────────────┐
         │                         │                         │
   ┌─────▼─────┐            ┌─────▼─────┐            ┌─────▼─────┐
   │ Metis API │            │  Metis    │            │  Metis    │
   │ (Fargate) │            │  Worker   │            │  Batch    │
   │ 1-10 tasks│            │ (Fargate) │            │ (Fargate) │
   └─────┬─────┘            └─────┬─────┘            └─────┬─────┘
         │                        │                         │
         │    ┌───────────────────┼─────────────────┐       │
         │    │                   │                  │       │
    ┌────▼────▼──┐    ┌──────────▼──┐    ┌──────────▼──────▼──┐
    │    RDS     │    │    Redis    │    │        SQS          │
    │ PostgreSQL │    │ ElastiCache │    │   (job dispatch)    │
    │ (pgvector) │    │             │    │                     │
    └────────────┘    └─────────────┘    └──────────┬──────────┘
                                                    │
                                         ┌──────────▼──────────┐
                                         │  RunPod Serverless   │
                                         │                      │
                                         │  TTS (Chatterbox)    │
                                         │  STT (Whisper)       │
                                         │  VLM (Qwen, Phi)     │
                                         │  Embeddings          │
                                         │  Audio Processing    │
                                         └──────────────────────┘
```

### Metis-Specific ECS Services

| Service      | Role                                                           | CPU      | Memory  | Scaling                       |
| ------------ | -------------------------------------------------------------- | -------- | ------- | ----------------------------- |
| metis-api    | REST API for course generation, management, queries            | 1-2 vCPU | 2-4 GB  | CPU-based, 2-10 tasks         |
| metis-worker | Background processing: lecture generation, refinement pipeline | 2-4 vCPU | 4-16 GB | SQS-depth-based, 1-10 tasks   |
| metis-batch  | Scheduled bulk generation and content refresh                  | 4 vCPU   | 16 GB   | EventBridge scheduled, 1 task |

### RunPod GPU Endpoints Used by Metis

From `minerva/infrastructure/runpod/endpoints.yaml`, Metis uses 11 endpoint
types:

| Endpoint              | GPU Tier                | Min/Max Workers | Purpose                           |
| --------------------- | ----------------------- | --------------- | --------------------------------- |
| tts-chatterbox        | AMPERE_24 (A4000/A5000) | 0/5             | Synthesized lecturer voices       |
| tts-parler            | AMPERE_24               | 0/3             | Natural voice synthesis           |
| stt-whisper           | AMPERE_24, ADA_24       | 0/10            | Speech transcription              |
| stt-whisper-realtime  | AMPERE_24               | 1/5             | Real-time streaming transcription |
| embeddings            | AMPERE_16               | 1/20            | Text embeddings for RAG           |
| embeddings-multimodal | AMPERE_24               | 0/5             | Image+text embeddings             |
| vlm-qwen              | AMPERE_48 (A40/A6000)   | 0/3             | Diagram understanding (72B model) |
| vlm-phi               | AMPERE_24               | 0/5             | Fast visual analysis              |
| vlm-moondream         | AMPERE_16               | 1/10            | Lightweight visual Q&A            |
| audio-diarization     | AMPERE_24               | 0/5             | Speaker diarization               |
| audio-enhancement     | AMPERE_16               | 0/8             | Audio noise reduction             |

---

## Multi-Region Considerations

### Data Residency

Educational content and user data must comply with regional data protection
regulations:

| Region                                | Regulation                                   | Requirements                                                                       |
| ------------------------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------- |
| EU (eu-west-1, eu-central-1)          | GDPR                                         | Data must reside in EU, right to erasure, DPO required, data processing agreements |
| US (us-east-1, us-west-2)             | FERPA, COPPA, state laws                     | Student records protection, parental consent for minors, California CCPA           |
| APAC (ap-southeast-1, ap-northeast-1) | PDPA (Singapore), APPI (Japan), PIPL (China) | Local storage for PII, cross-border transfer restrictions, consent requirements    |

Implementation:

- Deploy separate RDS instances per region (not cross-region replicas for PII)
- Use S3 bucket policies restricting objects to their origin region
- Tag all resources with `data-residency: <region>` for compliance auditing
- Course content (non-PII) can be replicated globally; user data stays regional
- Implement data classification: `public` (course catalog), `internal` (course
  content), `restricted` (user PII, assessment results)

### Latency

Multimedia lecture generation is latency-tolerant for batch operations but
latency-sensitive for interactive features:

| Operation                      | Latency Target     | Multi-Region Impact                    |
| ------------------------------ | ------------------ | -------------------------------------- |
| Course catalog browsing        | < 200ms            | CDN-cached, region-local               |
| Lecture playback (audio/video) | < 100ms first byte | CDN edge delivery                      |
| Real-time transcription        | < 500ms            | Requires regional RunPod endpoint      |
| Course generation (batch)      | Minutes to hours   | Region-local, latency irrelevant       |
| Semantic search                | < 300ms            | Region-local vector DB                 |
| API requests                   | < 500ms            | Route53 latency routing to nearest ALB |

### GPU Availability

RunPod GPU availability varies significantly by datacenter region:

| GPU Tier                    | US Availability | EU Availability | APAC Availability |
| --------------------------- | --------------- | --------------- | ----------------- |
| AMPERE_16 (A4000, RTX 3090) | High            | Medium          | Low-Medium        |
| AMPERE_24 (A5000, RTX 4090) | High            | Medium          | Medium            |
| AMPERE_48 (A40, A6000)      | Medium          | Low-Medium      | Low               |
| AMPERE_80 (A100)            | Medium          | Low             | Low               |
| ADA_24 (L4)                 | High            | Medium          | Medium            |
| ADA_48 (L40)                | Medium          | Low             | Low               |
| HOPPER_80 (H100)            | Low-Medium      | Low             | Very Low          |

Strategy:

- US regions serve as primary GPU compute; EU and APAC use RunPod's nearest
  available datacenter with `locations: null` (auto-select)
- For latency-critical endpoints (real-time STT, embeddings), pin
  `workers_min: 1` in each deployment region to avoid cold starts
- For batch endpoints (VLM, TTS generation), accept cross-region routing to
  wherever GPUs are available
- Monitor RunPod queue delays per region; if EU queue exceeds 30s, route batch
  jobs to US endpoints

---

## Recommended Deployment Topology

### US Region (Primary): us-east-1

The primary deployment region. All services fully operational.

```
us-east-1 (Primary)
├── ECS Cluster
│   ├── metis-api (Fargate, 3-10 tasks, 2 vCPU / 4 GB)
│   ├── metis-worker (Fargate, 2-10 tasks, 4 vCPU / 8 GB)
│   └── metis-batch (Fargate, scheduled, 4 vCPU / 16 GB)
├── RDS PostgreSQL (db.r6g.large, Multi-AZ, 2 read replicas)
├── ElastiCache Redis (cache.r6g.large, 2-node cluster, Multi-AZ)
├── S3 Buckets (courses, media, exports, logs)
├── ALB (HTTPS, WAF enabled)
├── SQS Queues (job dispatch + DLQ)
├── CloudWatch (dashboards, alarms, Container Insights)
└── Secrets Manager + SSM Parameter Store
```

RunPod GPU endpoints (US datacenter):

- All 11 endpoints active
- `embeddings` and `stt-whisper-realtime` with `workers_min: 1`
- `vlm-qwen` with `workers_max: 5` (primary generation region)

DR secondary in us-west-2:

- S3 replica buckets for courses and media
- RDS cross-region read replica (warm standby)
- Pre-provisioned ECS cluster (scaled to zero, ready for failover)

### EU Region: eu-west-1 (Ireland)

Full deployment for GDPR compliance and EU user latency.

```
eu-west-1
├── ECS Cluster
│   ├── metis-api (Fargate, 2-5 tasks, 1 vCPU / 2 GB)
│   ├── metis-worker (Fargate, 1-5 tasks, 2 vCPU / 4 GB)
│   └── metis-batch (Fargate, scheduled, 4 vCPU / 8 GB)
├── RDS PostgreSQL (db.r6g.large, Multi-AZ, 1 read replica)
├── ElastiCache Redis (cache.t4g.medium, 2-node cluster)
├── S3 Buckets (courses-eu, media-eu, logs-eu)
├── ALB (HTTPS, WAF enabled)
├── SQS Queues (job dispatch + DLQ)
└── CloudWatch (dashboards, alarms)
```

RunPod GPU endpoints (EU datacenter):

- Core endpoints: tts-chatterbox, stt-whisper, embeddings, vlm-phi,
  audio-enhancement
- `embeddings` with `workers_min: 1`
- Large model endpoints (vlm-qwen) routed to US if EU GPUs unavailable
- `workers_max` reduced to 60% of US values

### APAC Region: ap-southeast-1 (Singapore)

Lighter deployment optimized for latency to Southeast Asia, Japan, and
Australia.

```
ap-southeast-1
├── ECS Cluster
│   ├── metis-api (Fargate, 1-3 tasks, 1 vCPU / 2 GB)
│   ├── metis-worker (Fargate, 1-3 tasks, 2 vCPU / 4 GB)
│   └── metis-batch (Fargate, scheduled, 2 vCPU / 8 GB)
├── RDS PostgreSQL (db.r6g.medium, Multi-AZ, 0 read replicas)
├── ElastiCache Redis (cache.t4g.small, single node)
├── S3 Buckets (courses-apac, media-apac, logs-apac)
├── ALB (HTTPS, WAF enabled)
├── SQS Queues (job dispatch + DLQ)
└── CloudWatch (alarms only, no dashboards)
```

RunPod GPU endpoints (APAC):

- Minimal set: tts-chatterbox, stt-whisper, embeddings, vlm-phi
- All `workers_min: 0` (cost optimization; accept cold starts)
- Heavy GPU workloads (vlm-qwen, batch generation) routed to US
- `workers_max` reduced to 30% of US values

### Global Traffic Routing

```
Route53
├── api.metis.oshun.dev
│   ├── us-east-1  (latency-based routing, primary)
│   ├── eu-west-1  (latency-based routing)
│   └── ap-southeast-1 (latency-based routing)
│
├── cdn.metis.oshun.dev
│   └── CloudFront (global edge, origin: S3 per region)
│
└── Health checks
    ├── /health on each regional ALB (30s interval, 3 failure threshold)
    └── Automatic failover on health check failure
```

---

## Database Replication Strategy

### PostgreSQL (RDS)

Metis uses PostgreSQL with pgvector for course content storage, user data, and
vector embeddings.

#### Replication Topology

```
                     ┌──────────────────────┐
                     │   us-east-1 (Primary) │
                     │   db.r6g.large        │
                     │   Multi-AZ: Yes       │
                     │   Storage: 200 GB     │
                     └─────────┬─────────────┘
                               │
              ┌────────────────┼────────────────┐
              │                │                │
    ┌─────────▼──────┐  ┌─────▼──────┐  ┌──────▼─────────┐
    │ us-east-1      │  │ us-west-2  │  │ eu-west-1      │
    │ Read Replica 1 │  │ Cross-Rgn  │  │ Independent    │
    │ (read scale)   │  │ Replica    │  │ Primary        │
    │                │  │ (warm DR)  │  │ (GDPR data)    │
    └────────────────┘  └────────────┘  └────────────────┘
                                              │
                                        ┌─────▼──────┐
                                        │ eu-west-1  │
                                        │ Read       │
                                        │ Replica    │
                                        └────────────┘
```

#### Strategy by Data Type

| Data Type                            | Replication                                          | Rationale                                   |
| ------------------------------------ | ---------------------------------------------------- | ------------------------------------------- |
| Course catalog (metadata)            | Global sync via application-level replication        | Non-PII, needs low-latency reads everywhere |
| Course content (lessons, media refs) | Cross-region S3 replication + DB sync                | Large objects in S3, metadata in DB         |
| User accounts & PII                  | Region-local only, no cross-region replication       | GDPR/PDPA compliance                        |
| Assessment results                   | Region-local only                                    | Student data protection                     |
| Vector embeddings                    | Generated locally per region from replicated content | Avoids transferring large embedding data    |
| Usage analytics                      | Aggregated to us-east-1 via Kinesis/SQS (anonymized) | Central analytics, no PII transfer          |

#### Replication Configuration

For the us-east-1 primary:

```yaml
# prod.yaml
disaster_recovery:
  rds_replication:
    enabled: true
    destination_region: us-west-2
    multi_az: true
    backup_retention_days: 35
    copy_tags_to_snapshot: true
```

For eu-west-1 and ap-southeast-1, each region operates an independent RDS
primary. Course catalog data is synchronized using an application-level event
bus (SQS cross-region or EventBridge global endpoints) rather than database
replication, keeping PII isolated.

### Redis (ElastiCache)

Redis is used for caching, session state, and rate limiting. Each region
operates an independent Redis cluster. No cross-region replication.

| Region         | Node Type        | Cluster Size | Multi-AZ |
| -------------- | ---------------- | ------------ | -------- |
| us-east-1      | cache.r6g.large  | 2 nodes      | Yes      |
| eu-west-1      | cache.t4g.medium | 2 nodes      | Yes      |
| ap-southeast-1 | cache.t4g.small  | 1 node       | No       |

Cache warming strategy: On deployment, pre-populate frequently accessed course
catalog entries using a warmup Lambda triggered by CodeDeploy lifecycle hooks.

### Weaviate / Qdrant (Vector Database)

Vector search for semantic course discovery and RAG. Each region hosts its own
instance. Embeddings are generated locally from replicated course content to
avoid transferring large vector data.

---

## CDN and Edge Caching

### CloudFront Distribution

Metis generates multimedia content (audio lectures, animated diagrams,
presentation slides) that benefits heavily from edge caching.

```
CloudFront (Global Edge Network)
│
├── Behavior: /courses/*/media/*
│   ├── Origin: S3 bucket (region-specific)
│   ├── Cache Policy: Managed-CachingOptimized
│   ├── TTL: default 86400s (24h), max 604800s (7d)
│   ├── Origin Shield: us-east-1 (reduces origin load)
│   └── Compress: gzip, brotli
│
├── Behavior: /courses/*/audio/*
│   ├── Origin: S3 bucket (region-specific)
│   ├── Cache Policy: Custom (vary on Accept-Encoding, Range)
│   ├── TTL: default 604800s (7d) — audio rarely changes
│   └── Origin Request Policy: AllViewer (support Range requests)
│
├── Behavior: /api/*
│   ├── Origin: Regional ALB (latency-routed)
│   ├── Cache Policy: CachingDisabled (dynamic API)
│   ├── Origin Request Policy: AllViewerAndCloudFrontHeaders
│   └── TTL: 0 (pass-through)
│
└── Behavior: /courses/*/manifest.json
    ├── Origin: S3 bucket
    ├── Cache Policy: Custom
    ├── TTL: default 300s (5m) — manifests update on publish
    └── Invalidation: On course publish via Lambda@Edge
```

### Cache Invalidation

When a course is published or updated:

1. Metis worker publishes a `course.published` event to SNS
2. A Lambda function triggers CloudFront invalidation for `/courses/<id>/*`
3. Manifest files (`manifest.json`) have short TTL (5 minutes) as a safety net
4. Immutable content (audio files, images) uses content-hash filenames and never
   needs invalidation

### Edge Functions

Lambda@Edge functions at CloudFront for:

- **Viewer Request**: Geo-routing header injection (`X-Viewer-Country`), A/B
  testing for lecture formats
- **Origin Request**: Dynamic origin selection based on viewer region (route to
  nearest S3 bucket)
- **Origin Response**: Add `Cache-Control` headers for multimedia content,
  inject CORS headers

### Estimated CDN Metrics

| Metric                       | US     | EU     | APAC   |
| ---------------------------- | ------ | ------ | ------ |
| Expected cache hit ratio     | 85-92% | 80-88% | 75-85% |
| P50 latency (cached)         | 15ms   | 25ms   | 40ms   |
| P50 latency (origin fetch)   | 80ms   | 120ms  | 200ms  |
| Monthly transfer (estimated) | 500 GB | 200 GB | 100 GB |

---

## GPU Compute Distribution

### RunPod Region Strategy

RunPod operates datacenters across North America, Europe, and limited APAC
locations. The `locations: null` default in endpoint config allows RunPod to
route jobs to the nearest available datacenter.

#### Per-Region Endpoint Allocation

| Endpoint              | US           | EU           | APAC        | Notes                    |
| --------------------- | ------------ | ------------ | ----------- | ------------------------ |
| tts-chatterbox        | 0/5 workers  | 0/3 workers  | 0/2 workers | Core generation          |
| tts-parler            | 0/3 workers  | 0/2 workers  | --          | US/EU only               |
| stt-whisper           | 0/10 workers | 0/5 workers  | 0/3 workers | Batch transcription      |
| stt-whisper-realtime  | 1/5 workers  | 0/3 workers  | --          | Active worker in US only |
| embeddings            | 1/20 workers | 1/10 workers | 0/5 workers | Active worker in US+EU   |
| embeddings-multimodal | 0/5 workers  | 0/3 workers  | --          | US/EU only               |
| vlm-qwen              | 0/5 workers  | --           | --          | US only (48GB GPU)       |
| vlm-phi               | 0/5 workers  | 0/3 workers  | 0/2 workers | Lightweight VLM          |
| vlm-moondream         | 1/10 workers | 0/5 workers  | 0/3 workers | Active worker in US      |
| audio-diarization     | 0/5 workers  | 0/3 workers  | --          | US/EU only               |
| audio-enhancement     | 0/8 workers  | 0/5 workers  | 0/3 workers | Noise reduction          |

#### Cross-Region GPU Routing

For workloads where regional GPU availability is insufficient:

```
APAC Request
    │
    ▼
metis-worker (ap-southeast-1)
    │
    ├── Check: APAC RunPod queue delay < 30s?
    │   ├── Yes → Route to APAC RunPod endpoint
    │   └── No  → Route to US RunPod endpoint
    │
    └── For vlm-qwen (48GB GPU):
        └── Always route to US (APAC lacks A40/A6000 capacity)
```

Implementation: The Metis RunPod client library checks endpoint queue depth via
the RunPod status API before dispatching. If the preferred region's queue delay
exceeds a configurable threshold (default 30s), the job is routed to the primary
US endpoint.

#### FlashBoot Optimization

RunPod's FlashBoot feature provides sub-500ms cold starts when
`workers_max >= 3`. Endpoints with `workers_max < 3` will experience full cold
starts (30-60s). APAC endpoints with reduced `workers_max` may not qualify for
FlashBoot. Mitigate with periodic keepalive pings from a CloudWatch Events rule.

### GPU Cost Optimization

- **Active workers** (workers_min > 0) receive a 30% discount from RunPod but
  are billed continuously. Reserve only for latency-critical endpoints.
- **Flex workers** scale to zero and are billed per-second of execution. Use for
  all batch and non-realtime workloads.
- **Spot-like pricing**: RunPod's Community Cloud GPUs cost 50-70% less than
  Secure Cloud but have less availability guarantees. Use Community Cloud for
  dev/staging, Secure Cloud for production.

---

## Estimated Costs Per Region

### US Region (us-east-1) -- Primary

| Service               | Configuration                  | Monthly Cost     |
| --------------------- | ------------------------------ | ---------------- |
| ECS Fargate (API)     | 3 tasks x 2 vCPU / 4 GB        | $290             |
| ECS Fargate (Worker)  | 2 tasks x 4 vCPU / 8 GB        | $390             |
| ECS Fargate (Batch)   | 4 vCPU / 16 GB, 4h/day         | $120             |
| RDS PostgreSQL        | db.r6g.large, Multi-AZ, 200 GB | $580             |
| RDS Read Replicas (2) | db.r6g.large x 2               | $460             |
| ElastiCache Redis     | cache.r6g.large, 2 nodes       | $290             |
| ALB                   | 1 ALB + LCUs                   | $40              |
| NAT Gateway           | 3 gateways + data processing   | $180             |
| S3 Storage            | 500 GB + requests              | $30              |
| CloudWatch            | Logs, metrics, dashboards      | $80              |
| Secrets Manager + SSM | ~50 secrets                    | $25              |
| WAF                   | Web ACL + rules                | $30              |
| **AWS Subtotal**      |                                | **$2,515**       |
| RunPod Active Workers | 3 endpoints x 1 min worker     | $450             |
| RunPod Flex Workers   | Variable GPU usage             | $300-800         |
| **RunPod Subtotal**   |                                | **$750-1,250**   |
| **US Total**          |                                | **$3,265-3,765** |

### EU Region (eu-west-1)

| Service               | Configuration                  | Monthly Cost     |
| --------------------- | ------------------------------ | ---------------- |
| ECS Fargate (API)     | 2 tasks x 1 vCPU / 2 GB        | $100             |
| ECS Fargate (Worker)  | 1 task x 2 vCPU / 4 GB         | $100             |
| ECS Fargate (Batch)   | 4 vCPU / 8 GB, 2h/day          | $40              |
| RDS PostgreSQL        | db.r6g.large, Multi-AZ, 100 GB | $520             |
| RDS Read Replica (1)  | db.r6g.large x 1               | $230             |
| ElastiCache Redis     | cache.t4g.medium, 2 nodes      | $100             |
| ALB                   | 1 ALB + LCUs                   | $35              |
| NAT Gateway           | 2 gateways + data processing   | $120             |
| S3 Storage            | 200 GB + requests              | $15              |
| CloudWatch            | Logs, metrics, dashboards      | $50              |
| WAF                   | Web ACL + rules                | $30              |
| **AWS Subtotal**      |                                | **$1,340**       |
| RunPod Active Workers | 1 endpoint x 1 min worker      | $150             |
| RunPod Flex Workers   | Variable GPU usage             | $150-400         |
| **RunPod Subtotal**   |                                | **$300-550**     |
| **EU Total**          |                                | **$1,640-1,890** |

### APAC Region (ap-southeast-1)

| Service              | Configuration                  | Monthly Cost |
| -------------------- | ------------------------------ | ------------ |
| ECS Fargate (API)    | 1 task x 1 vCPU / 2 GB         | $55          |
| ECS Fargate (Worker) | 1 task x 2 vCPU / 4 GB         | $100         |
| ECS Fargate (Batch)  | 2 vCPU / 8 GB, 1h/day          | $15          |
| RDS PostgreSQL       | db.r6g.medium, Multi-AZ, 50 GB | $320         |
| ElastiCache Redis    | cache.t4g.small, 1 node        | $30          |
| ALB                  | 1 ALB + LCUs                   | $35          |
| NAT Gateway          | 1 gateway + data processing    | $60          |
| S3 Storage           | 100 GB + requests              | $10          |
| CloudWatch           | Alarms only                    | $20          |
| WAF                  | Web ACL + rules                | $30          |
| **AWS Subtotal**     |                                | **$675**     |
| RunPod Flex Workers  | Variable GPU usage (no active) | $100-300     |
| **RunPod Subtotal**  |                                | **$100-300** |
| **APAC Total**       |                                | **$775-975** |

### Global Services (Shared)

| Service                                | Monthly Cost               |
| -------------------------------------- | -------------------------- |
| CloudFront (CDN)                       | $100-250 (800 GB transfer) |
| Route53 (DNS + health checks)          | $15                        |
| S3 Cross-Region Replication (transfer) | $20-50                     |
| AWS Shield Standard                    | $0 (included)              |
| **Global Total**                       | **$135-315**               |

### Total Multi-Region Cost Summary

| Tier                        | Regions               | Monthly Estimate |
| --------------------------- | --------------------- | ---------------- |
| US only (single region)     | us-east-1             | $3,265-3,765     |
| US + EU (two regions)       | us-east-1 + eu-west-1 | $5,040-5,970     |
| US + EU + APAC (full)       | All three             | $5,815-6,945     |
| US + EU + APAC + CDN/Global | All + global services | $5,950-7,260     |

### Cost Optimization Levers

| Optimization                      | Savings                  | Trade-off                                    |
| --------------------------------- | ------------------------ | -------------------------------------------- |
| Fargate Spot for workers          | 50-70% on worker compute | Possible task interruption (2-min warning)   |
| Reserved Instances (RDS)          | 30-40% on database       | 1-year commitment                            |
| Savings Plans (Fargate)           | 20-30% on ECS compute    | 1-year commitment                            |
| RunPod Community Cloud            | 50-70% on GPU compute    | Less availability, shared infrastructure     |
| Reduce APAC to read-only (no GPU) | ~$400/month              | APAC users see higher latency for generation |
| Scale APAC to zero off-peak       | ~$200/month              | Cold start latency during off-peak           |
| S3 Intelligent-Tiering            | 10-30% on storage        | Small monitoring fee per object              |

---

## Deployment Checklist

When enabling multi-region for Metis:

1. **Bootstrap CDK** in each target region

   ```bash
   cdk bootstrap aws://ACCOUNT_ID/us-east-1
   cdk bootstrap aws://ACCOUNT_ID/eu-west-1
   cdk bootstrap aws://ACCOUNT_ID/ap-southeast-1
   ```

2. **Update config** to enable multi-region

   ```yaml
   multi_region:
     enabled: true
     primary_region: us-east-1
     regions:
       - us-east-1
       - eu-west-1
       - ap-southeast-1
     deployment_mode: active-active
   ```

3. **Deploy primary region first**, then secondary regions

   ```bash
   MINERVA_ENV=prod AWS_DEFAULT_REGION=us-east-1 cdk deploy --all
   MINERVA_ENV=prod AWS_DEFAULT_REGION=eu-west-1 cdk deploy --all
   MINERVA_ENV=prod AWS_DEFAULT_REGION=ap-southeast-1 cdk deploy --all
   ```

4. **Enable global distribution** (Route53)

   ```yaml
   global_distribution:
     enabled: true
     routing_policy: latency
   ```

5. **Configure CloudFront** with multi-origin failover

6. **Provision RunPod endpoints** per region via Pulumi or API

7. **Validate** health checks, latency routing, and failover behavior

8. **Monitor** per-region dashboards and cost allocation tags
