# Estimate Infrastructure Cost

<!--
MAINTENANCE: Review pricing quarterly (March, June, September, December)
Last reviewed: 2025-01
Next review: 2025-04
-->

## Purpose

Get a detailed cost estimate for cloud infrastructure before deployment, including baseline, normal, and peak usage scenarios.

## Prompt Template

```
I need to estimate the monthly cost for the following infrastructure:

**Application**: {APPLICATION_NAME}

**Infrastructure Components**:
{LIST_RESOURCES}

**Expected Usage**:
- Monthly active users: {MAU}
- API requests per month: {API_REQUESTS}
- Data storage: {STORAGE_GB} GB
- Bandwidth: {BANDWIDTH_GB} GB/month
- Build/deployment frequency: {BUILDS_PER_MONTH} builds/month

**Environments**:
- Development: {DEV_REQUIREMENTS}
- Staging: {STAGING_REQUIREMENTS}
- Production: {PRODUCTION_REQUIREMENTS}

**Please provide**:
1. Cost breakdown by service for each environment
2. Baseline cost (minimal usage)
3. Normal cost (expected usage)
4. Peak cost (2x expected usage)
5. Cost optimization recommendations
6. Comparison with alternative providers/architectures
7. Budget alert recommendations

**Additional context**:
{OPTIONAL_CONTEXT}
```

## Variables

- `{APPLICATION_NAME}`: Name of your application (e.g., "E-commerce platform")
- `{LIST_RESOURCES}`: List of infrastructure components needed:
  - Database (type, size)
  - Frontend hosting (platform)
  - Backend/API (platform, compute)
  - Storage (buckets, CDN)
  - Other services (auth, email, etc.)
- `{MAU}`: Monthly active users
- `{API_REQUESTS}`: Estimated API requests per month
- `{STORAGE_GB}`: Total storage needed in GB
- `{BANDWIDTH_GB}`: Monthly bandwidth in GB
- `{BUILDS_PER_MONTH}`: How often you deploy
- `{DEV_REQUIREMENTS}`: Development environment requirements
- `{STAGING_REQUIREMENTS}`: Staging environment requirements
- `{PRODUCTION_REQUIREMENTS}`: Production environment requirements
- `{OPTIONAL_CONTEXT}`: Any additional context (traffic patterns, special requirements)

## Example Usage

**Input**:
```
I need to estimate the monthly cost for the following infrastructure:

**Application**: SaaS Task Management App

**Infrastructure Components**:
- PostgreSQL database (Supabase)
- Next.js frontend (Vercel)
- File uploads storage (Cloudflare R2)
- CDN (Cloudflare)
- Authentication (Supabase Auth)
- Real-time updates (Supabase Realtime)

**Expected Usage**:
- Monthly active users: 10,000
- API requests per month: 5,000,000
- Data storage: 50 GB (database) + 200 GB (file uploads)
- Bandwidth: 500 GB/month
- Build/deployment frequency: 100 builds/month

**Environments**:
- Development: Free tiers where possible
- Staging: Minimal paid tiers for testing
- Production: Full features, high availability

**Please provide**:
1. Cost breakdown by service for each environment
2. Baseline cost (minimal usage)
3. Normal cost (expected usage)
4. Peak cost (2x expected usage)
5. Cost optimization recommendations
6. Comparison with alternative providers/architectures
7. Budget alert recommendations

**Additional context**:
- Expecting 20% month-over-month growth
- Most traffic from US and Europe
- Need SOC2 compliance (may require Team tier for Supabase)
```

**Expected Output**:

```
# Infrastructure Cost Estimate

## Cost Breakdown

### Development Environment
- **Supabase Free**: $0/month
  - 500 MB database
  - 1 GB storage
  - 2 GB bandwidth
- **Vercel Hobby**: $0/month
  - Unlimited deployments
  - 100 GB bandwidth
- **Cloudflare Free**: $0/month
  - Unlimited bandwidth
  - 100k Workers requests/day

**Total Development**: $0/month

### Staging Environment
- **Supabase Pro**: $25/month
  - 8 GB database (adequate for staging)
  - 100 GB storage
  - 250 GB bandwidth
- **Vercel Pro**: $20/month
  - 1 TB bandwidth
  - 6000 build minutes
- **Cloudflare Workers Paid**: $5/month
  - 10M requests included
  - Minimal overage expected

**Total Staging**: $50/month

### Production Environment

**Baseline (Minimal Usage)**:
- Supabase Pro: $25/month
- Vercel Pro: $20/month
- Cloudflare Workers: $5/month
- Cloudflare R2: $3/month (200 GB storage)
**Total Baseline**: $53/month

**Normal (Expected Usage - 10k MAU, 5M requests/month)**:
- **Supabase Pro**: $35/month
  - Base: $25
  - Database overage: 50 GB → (50-8) × $0.125 = $5.25
  - Storage overage: 200 GB → (200-100) × $0.021 = $2.10
  - Bandwidth overage: 500 GB → (500-250) × $0.09 = $22.50
  - **Subtotal**: $54.85
- **Vercel Pro**: $50/month
  - Base: $20
  - Bandwidth overage: 500 GB (within 1 TB included)
  - Function execution: Minimal
  - **Subtotal**: $20
- **Cloudflare Workers**: $7.50/month
  - Base: $5
  - Requests overage: (5M - 10M = 0, within included)
  - **Subtotal**: $5
- **Cloudflare R2**: $6/month
  - Storage: 200 GB × $0.015 = $3
  - Class B operations: 5M × $0.36/M = $1.80
  - Egress: $0 (no egress fees!)
  - **Subtotal**: $4.80

**Total Normal**: $84.65/month

**Peak (2x Usage - 20k MAU, 10M requests/month)**:
- **Supabase Pro**: $85/month
  - Bandwidth doubles: (1000-250) × $0.09 = $67.50
- **Vercel Pro**: $40/month
  - Bandwidth overage: (1000-1000) = $0
- **Cloudflare Workers**: $10/month
  - Requests overage: (10M-10M) × $0.50/M = $0
- **Cloudflare R2**: $8/month
  - Operations double: 10M × $0.36/M = $3.60

**Total Peak**: $143/month

## Cost Optimization Recommendations

1. **Use Cloudflare R2 for file storage** (already in plan)
   - Savings vs S3: ~$90/month on 1 TB egress
   - No egress fees = predictable costs

2. **Optimize Supabase bandwidth**
   - Implement aggressive client-side caching
   - Use Cloudflare Workers as caching layer
   - Potential savings: $20-30/month

3. **Use Vercel Edge Config for config data**
   - Reduce database reads
   - Included in Vercel Pro

4. **Implement image optimization**
   - Use Vercel Image Optimization or Cloudflare Images
   - Reduce bandwidth by 40-60%

5. **Set up database connection pooling**
   - Reduce database resource usage
   - Enable with Supabase Supavisor

## Alternative Architectures

### Alternative 1: AWS-based
- RDS PostgreSQL: $50/month (db.t3.medium)
- Amplify Hosting: $15/month
- S3 + CloudFront: $30/month
- Cognito Auth: $50/month (MAU-based)
**Total**: ~$145/month (70% more expensive)

### Alternative 2: Self-hosted
- DigitalOcean Droplet: $24/month (4GB RAM)
- Managed PostgreSQL: $15/month
- Spaces (storage): $5/month
**Total**: ~$44/month (50% cheaper but requires ops overhead)

**Recommendation**: Stick with Supabase + Vercel + Cloudflare for best balance of cost, features, and developer experience.

## Budget Alert Recommendations

### Development
- No budget alerts needed (free tier)

### Staging
- Alert at $60/month (20% buffer)
- Email: dev-team@example.com

### Production
- **Warning alert** at $100/month (baseline + 90%)
  - Email: dev-team@example.com
- **Critical alert** at $150/month (peak threshold)
  - Email: dev-team@example.com, finance@example.com
- **Hard limit** at $200/month
  - Investigate immediately, may indicate attack or bug

## Implementation

```bash
# Set budget in Pulumi config
pulumi config set monthlyBudget 150  # Production

# Set up cost tracking tags
pulumi config set costCenter engineering
pulumi config set owner platform-team
```

## Cost Tracking

Monitor these metrics weekly:
- Supabase database size (alert if >80% of tier limit)
- Bandwidth usage (alert if >80% of included amount)
- API request volume (alert if unusual spike)
- Build frequency (optimize if exceeding needs)
```

## Tips

- **Be specific about usage patterns**: Daily active users, peak hours, traffic sources
- **Include growth projections**: Plan for 2-3x growth over 6 months
- **Consider compliance requirements**: SOC2, HIPAA, GDPR may require higher tiers
- **Factor in operational costs**: Monitoring, alerting, logging add 10-20% overhead
- **Request multiple scenarios**: Compare providers and architectures
- **Validate with provider calculators**: Cross-check AI estimates with official pricing tools

## Tags

#infrastructure #cost-estimation #budgeting #planning
