Optimizing costs

From ancoleman/ai-design-components · View interactive version

Optimizing costs is an AI agent skill from the GitHub repository ancoleman/ai-design-components. Optimize cloud infrastructure costs through FinOps practices, commitment discounts, right-sizing, and automated cost management. Use when reducing cloud spend, implementing budget controls, or establishing cost visibility across AWS, Azure, GCP, and Kubernetes environments.

How to use this skill

Skill file

Cost Optimization

Purpose

Cloud cost optimization transforms uncontrolled spending into strategic resource allocation through the FinOps lifecycle: Inform, Optimize, and Operate. This skill provides decision frameworks for commitment-based discounts (Reserved Instances, Savings Plans), right-sizing strategies, Kubernetes cost management, and automated cost governance across multi-cloud environments.

When to Use This Skill

Invoke cost-optimization when:

FinOps Principles

The FinOps Lifecycle

┌─────────────────────────────────────────────────────┐
│  INFORM → OPTIMIZE → OPERATE (continuous loop)      │
│    ↓         ↓           ↓                          │
│ Visibility  Action   Automation                     │
└─────────────────────────────────────────────────────┘

Inform Phase: Establish cost visibility

Optimize Phase: Take action on cost drivers

Operate Phase: Automate and govern

Core FinOps Principles

  1. Collaboration: Cross-functional teams (finance, engineering, operations, product)
  2. Accountability: Teams own the cost of their services
  3. Transparency: All costs visible and understandable to stakeholders
  4. Optimization: Continuous improvement of cost efficiency

For detailed FinOps maturity models and organizational structures, see references/finops-foundations.md.

Cost Optimization Strategies

1. Commitment-Based Discounts

Reserved Instances (RIs): 40-72% discount for 1-3 year commitments

Savings Plans: Flexible compute commitments

GCP Committed Use Discounts (CUDs): 25-70% discount

Decision Framework:

Reserve when:
├─ Workload is production-critical (24/7 uptime required)
├─ Usage is predictable (stable baseline over 6+ months)
├─ Architecture is stable (unlikely to change instance types)
└─ Financial commitment acceptable (1-3 year lock-in)

Use On-Demand when:
├─ Development/testing environments
├─ Unpredictable spiky workloads
├─ Short-term projects (<6 months)
└─ Evaluating new instance types

For detailed commitment strategies and RI coverage analysis, see references/commitment-strategies.md.

2. Spot and Preemptible Instances

Discount: 70-90% off on-demand pricing (interruptible with 2-minute warning)

Use Spot For: CI/CD workers, batch jobs, ML training (with checkpointing), Kubernetes workers, data analytics

Avoid Spot For: Stateful databases, real-time services, long-running jobs without checkpointing

Best Practices:

3. Right-Sizing Strategies

Target Utilization: 60-80% average (leave headroom for spikes)

Compute Right-Sizing:

Database Right-Sizing:

Kubernetes Right-Sizing:

Storage Right-Sizing:

Right-Sizing Tools:

4. Kubernetes Cost Management

Resource Requests and Limits:

# Set requests = average usage (enables efficient bin-packing)
resources:
  requests:
    cpu: 500m        # 0.5 CPU cores (average usage)
    memory: 1Gi      # 1 GiB memory (average usage)
  limits:
    cpu: 1500m       # 1.5 CPU cores (3x requests, allows bursting)
    memory: 3Gi      # 3 GiB memory (3x requests)

Namespace Quotas: Prevent runaway resource consumption

Cluster Autoscaling:

Cost Visibility:

For detailed Kubernetes cost optimization patterns, see references/kubernetes-cost-optimization.md.

Cost Visibility and Monitoring

Tagging for Cost Allocation

Required Tags:

Enable Cost Allocation Tags:

For comprehensive tagging strategies, see references/tagging-for-cost-allocation.md.

Monitoring and Dashboards

Native Cloud Tools:

Third-Party Platforms:

Key Metrics to Track:

Budget Alerts and Anomaly Detection

Cascading Budget Alerts:

50% of budget  → Email to team lead (informational)
75% of budget  → Email + Slack to team (warning)
90% of budget  → Email + Slack + PagerDuty (urgent)
100% of budget → Automated shutdown (non-prod only) or escalation

Anomaly Detection: Alert on unexpected cost spikes

Budget Granularity:

Decision Frameworks

Framework 1: Commitment Discount Decision Tree

Should we purchase Reserved Instances / Savings Plans?

STEP 1: Analyze Historical Usage (6-12 months)
├─ Identify steady-state baseline (minimum usage)
├─ Exclude spiky/seasonal workloads
└─ Calculate: (baseline usage) / (total usage) = commitment %

STEP 2: Choose Commitment Type
├─ RESERVED INSTANCES
│   ├─ Pros: Highest discount (up to 72%)
│   ├─ Cons: Instance type locked (unless convertible)
│   └─ Use for: Databases, stable production workloads
│
├─ SAVINGS PLANS
│   ├─ Pros: Flexible (across instance types, regions)
│   ├─ Cons: Slightly lower discount than RI
│   └─ Use for: Compute workloads, Lambda, Fargate
│
└─ COMMITTED USE DISCOUNTS (GCP)
    ├─ Resource-based: vCPU/memory commitments
    └─ Spend-based: Dollar amount commitments

STEP 3: Determine Commitment Period
├─ 1-year commitment
│   ├─ Lower discount (40-50%)
│   └─ Less risk if architecture changes
│
└─ 3-year commitment
    ├─ Higher discount (60-72%)
    └─ Only for mature, stable workloads

STEP 4: Monitor and Optimize
├─ Target >95% RI/Savings Plan utilization
├─ Sell unused RIs on AWS Reserved Instance Marketplace
└─ Adjust commitments quarterly based on usage trends

Framework 2: Right-Sizing Priority Matrix

Cost Impact vs. Effort:

High Impact, Low Effort (DO FIRST):

High Impact, Medium Effort (DO SECOND):

Low Impact, High Effort (DO LAST):

Weekly Optimization Routine:

  1. Delete idle resources (automated script)
  2. Review top 10 cost drivers (manual analysis)
  3. Right-size 3-5 instances/week (incremental approach)
  4. Monitor impact (cost trend over 4 weeks)

Framework 3: Spot vs. On-Demand Decision

Should this workload use Spot/Preemptible instances?

├─ Is the workload fault-tolerant?
│   ├─ NO → Use On-Demand
│   └─ YES → Continue
│
├─ Is the workload stateless (or has checkpointing)?
│   ├─ NO → Use On-Demand (data loss risk)
│   └─ YES → Continue
│
├─ Can the workload handle interruptions gracefully?
│   ├─ NO → Use On-Demand
│   └─ YES → Continue
│
└─ Workload Type Assessment:
    ├─ Batch Jobs / CI/CD → ✅ Use Spot (70-90% savings)
    ├─ ML Training → ✅ Use Spot (with checkpointing)
    ├─ Kubernetes Workers → ✅ Use Spot (mixed with on-demand)
    ├─ Production API Servers → ⚠️ Mixed fleet (70% spot, 30% on-demand)
    ├─ Databases → ❌ Use On-Demand (or Reserved)
    └─ Real-time Services → ❌ Use On-Demand (or Reserved)

Tool Selection Guide

By Platform

| Platform | Cost Visibility | Right-Sizing | Automation |

|----------|----------------|--------------|------------|

| AWS | Cost Explorer, CUR | Compute Optimizer | AWS Budgets, Lambda cleanup |

| Azure | Cost Management | Azure Advisor | Azure Policy, Automation |

| GCP | Cloud Billing | Recommender | Budget Alerts, Cloud Functions |

| Kubernetes | Kubecost, OpenCost | VPA | Cluster Autoscaler |

| Multi-Cloud | CloudZero, CloudHealth | Densify | ParkMyCloud |

By Use Case

| Use Case | Recommended Tool | Key Feature |

|----------|------------------|-------------|

| K8s cost visibility | Kubecost | Real-time namespace cost allocation |

| Terraform cost estimation | Infracost | PR comments with cost diffs |

| Multi-cloud aggregation | CloudHealth | Unified cost view across AWS/Azure/GCP |

| Automated optimization | nOps (AWS), CAST AI (K8s) | ML-based automation |

| Unit cost economics | CloudZero | Cost per customer/transaction tracking |

| Spot instance management | Spot.io | Automated spot orchestration |

For detailed tool comparisons and selection criteria, see references/tools-comparison.md.

Cloud-Specific Tactics

AWS Optimization Tactics

  1. Enable Cost & Usage Reports (CUR): Export detailed billing to S3
  2. Use AWS Compute Optimizer: ML-based EC2 rightsizing recommendations
  3. Implement Savings Plans: More flexible than Reserved Instances
  4. S3 Intelligent-Tiering: Automatic storage class optimization
  5. Lambda Right-Sizing: Adjust memory allocation (CPU scales proportionally)
  6. EBS gp3 Migration: 20% cheaper than gp2 with same performance

Azure Optimization Tactics

  1. Enable Azure Advisor: VM rightsizing and reserved instance recommendations
  2. Azure Hybrid Benefit: Bring Windows Server licenses for discounts
  3. Dev/Test Pricing: Reduced rates for non-production workloads
  4. Azure Spot VMs: Up to 90% discount for interruptible workloads
  5. Storage Lifecycle Management: Auto-tier blobs to cool/archive tiers

GCP Optimization Tactics

  1. Export Billing to BigQuery: Custom cost analysis with SQL
  2. Sustained Use Discounts: Automatic 20-30% discount (no commitment)
  3. Committed Use Discounts: 52-70% savings for 3-year commitments
  4. Preemptible VMs: Up to 91% discount for batch workloads
  5. GCP Recommender: Idle VM detection and rightsizing advice

For cloud-specific deep dives, see references/cloud-specific-tactics.md.

Implementation Checklist

Phase 1: Establish Visibility (Week 1-2)

Phase 2: Set Up Governance (Week 2-3)

Phase 3: Quick Wins (Week 3-4)

Phase 4: Commitment Discounts (Month 2)

Phase 5: Automation (Month 2-3)

Phase 6: Continuous Optimization (Ongoing)

Common Pitfalls

Pitfall 1: No Cost Visibility

❌ Problem: Finance team sees cloud bill at end of month, surprises everywhere

✅ Solution: Deploy real-time cost dashboards, daily Slack reports to engineering teams

Pitfall 2: Reserved Instance Underutilization

❌ Problem: Purchased 100 RIs, only using 60 (40% wasted commitment)

✅ Solution: Monitor RI utilization weekly (target >95%), sell unused RIs on marketplace

Pitfall 3: Missing Kubernetes Resource Requests

❌ Problem: Pods with no requests set → inefficient bin-packing → wasted nodes

✅ Solution: Use VPA to auto-generate recommendations, enforce via admission control

Pitfall 4: Idle Resources Not Cleaned Up

❌ Problem: 50 stopped EC2 instances (still paying for EBS), 200 unattached volumes

✅ Solution: Weekly automated cleanup of idle resources >7 days old

Pitfall 5: No Budget Alerts

❌ Problem: Accidentally left test cluster running, $10K bill surprise

✅ Solution: Budget alerts at 50%, 75%, 90%, 100% with Slack/PagerDuty notifications

Related Skills

Examples

See examples/ directory for:

Scripts

See scripts/ directory for:

Key Takeaways

  1. FinOps is a Culture: Collaboration between finance, engineering, and operations
  2. Visibility First: Can't optimize what can't measure (tags + dashboards mandatory)
  3. Commitment = Savings: Reserved Instances/Savings Plans provide 40-72% discounts
  4. Right-Size Continuously: Target 60-80% utilization (leave headroom for spikes)
  5. Automate Cleanup: Idle resources are 100% waste (weekly automated deletion)
  6. Kubernetes Costs Hidden: Use Kubecost/OpenCost for namespace-level visibility
  7. Shift-Left Cost Awareness: Infracost in CI/CD prevents surprise cost increases
  8. Budget Alerts Prevent Overspend: Cascading notifications at 50%, 75%, 90%, 100%
  9. Spot for Fault-Tolerant Workloads: 70-90% discount (CI/CD, batch jobs, ML training)
  10. Unit Cost Metrics Drive Value: Track cost per customer, cost per transaction
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.