agentleFS
borhen68borhen68/SkillEngine/skills/cost-optimization/SKILL.md

cost-optimization

Skill17 starsChanged 6 months agoMITView on GitHub

Guides systematic cloud and infrastructure cost reduction. Use when cloud bills are growing unpredictably, when rightsizing resources, when evaluating reserved capacity, or when building cost-aware architecture. Use when you need to optimize spend without sacrificing reliability or performance.

16 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use incident-response, git-workflow and 3 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • AnthropicSkill

    incident-response

    Run an incident response workflow — triage, communicate, and write postmortem. Trigger with "we have an incident", "production is down", an alert that needs severity assessment, a status update mid-incident, or when writing a blameless postmortem after resolution.

    Also in 4 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 5 projects that use this

  • OpenAISkill

    observability

    Vercel Observability expert guidance — Drains (logs, traces, speed insights, web analytics), Web Analytics, Speed Insights, runtime logs, custom events, OpenTelemetry integration, and monitoring dashboards. Use when instrumenting, debugging, or optimizing application performance and user experience on Vercel.

    Also in 3 projects that use this

  • MicrosoftSkill

    api-design

    Guide for designing and documenting RESTful APIs. Use when asked to design an API, create endpoints, or document an API.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After an audit reveals "surprise" charges (data transfer, API calls, storage)

    line 23
  2. Distinctive:

    Run through this checklist systematically:

    line 57
  3. Distinctive:

    Every optimization must be measurable:

    line 201
  4. Distinctive:

    No tagging strategy (can't allocate costs to teams/products)

    line 279
  5. Distinctive:

    All environments run 24/7 (dev/staging should auto-shutdown)

    line 281
  6. Distinctive:

    No auto-scaling (manually sized for peak, paying for peak 24/7)

    line 284

“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cost Optimization

Overview

Cost optimization is not about being cheap — it's about spending money where it creates value and eliminating waste. In cloud environments, costs compound silently: oversized instances, forgotten dev environments, unoptimized storage tiers, and data transfer charges that nobody tracks. This skill provides a systematic approach to finding and eliminating waste while maintaining (or improving) system reliability.

The 80/20 rule of cloud costs: 80% of your bill comes from 20% of your resources. Focus on the big items first.

When to Use

  • Monthly cloud bill has grown > 20% without corresponding traffic growth
  • Setting up new infrastructure and want cost-aware defaults
  • Reviewing architecture for a system that's been running > 6 months
  • Preparing for scaling events (launch, Black Friday, viral growth)
  • Evaluating multi-cloud vs single-cloud strategies
  • After an audit reveals "surprise" charges (data transfer, API calls, storage)

NOT for:

  • Systems where reliability is worth any cost (life-critical, financial trading)
  • One-time cost reduction without ongoing monitoring (costs creep back)

The Cost Optimization Process

Step 1: Measure and Allocate

You can't optimize what you can't measure. Before changing anything:

COST ALLOCATION FRAMEWORK:
├── Tag everything (owner, environment, product, cost-center)
├── Enable detailed billing exports (hourly granularity)
├── Set up cost anomaly detection
├── Allocate shared costs (network, monitoring, platform)
└── Create per-team visibility dashboards

Key metrics to track:

MetricWhy It MattersTarget
Cost per requestEfficiency of serving trafficTrending down
Cost per userUnit economicsTrending down
Idle resource %Waste identification< 10%
Storage $/GBTier optimizationMatch workload pattern
Data transferOften the "surprise" line item< 10% of total

Step 2: Identify Waste

Run through this checklist systematically:

Compute Waste:

  • Instances with average CPU < 20% over 7 days
  • Instances with memory utilization < 40%
  • Running instances in dev/staging outside business hours
  • Over-provisioned container requests (K8s)
  • Unused auto-scaling groups with min-size > 0
  • Legacy instance types (newer generations are cheaper per performance unit)

Storage Waste:

  • Unattached volumes > 30 days old
  • Snapshots without retention policies
  • Objects in hot storage with no access in 90 days
  • Database instances with storage utilization < 30%
  • Logs stored indefinitely without lifecycle policies

Network Waste:

  • Cross-AZ traffic that could be co-located
  • Data transfer to internet instead of CDN
  • NAT Gateway traffic that could use VPC endpoints
  • Cross-region replication that's not needed
  • Egress charges from services that could use private connectivity

Licensing/Reserved Waste:

  • On-demand instances that could use reserved capacity
  • Reserved capacity for services that are being decommissioned
  • Database licenses where open-source alternatives suffice
  • Unused SaaS subscriptions (monitoring, CI/CD, etc.)

Step 3: Rightsize Resources

RIGHTSIZING WORKFLOW:
1. Collect metrics (CPU, memory, disk I/O, network) for 14+ days
2. Identify peak vs average vs p99 usage patterns
3. Match instance/container size to actual needs + 20% headroom
4. Test the smaller size in staging under load
5. Deploy to production with monitoring
6. Observe for 48 hours, adjust if needed

Rightsizing examples:

# Before: c5.2xlarge (8 vCPU, 16 GB) — $0.34/hour
# Metrics show: 15% CPU avg, 45% memory avg, never bursts above 40%
# After: c5.large (2 vCPU, 4 GB) — $0.085/hour
# Savings: 75% for this instance

# Kubernetes: Adjust resource requests
# Before:
resources:
  requests:
    cpu: 2000m      # Never uses more than 500m
    memory: 8Gi     # Uses 2Gi consistently

# After:
resources:
  requests:
    cpu: 750m       # 50% overhead on observed peak
    memory: 3Gi     # 50% overhead on observed peak
  limits:
    cpu: 1500m
    memory: 6Gi

Step 4: Optimize Storage Tiers

Match storage to access patterns:

DATA ACCESS PATTERN → STORAGE TIER
─────────────────────────────────────────────────
Frequently accessed (< 7 days)    → Hot / Standard
Occasionally accessed (7-90 days) → Warm / Infrequent Access
Rarely accessed (90+ days)        → Cold / Archive
Never accessed (backup only)      → Glacier / Deep Archive

Storage optimization examples:

# S3 Lifecycle Policy
{
  "Rules": [
    {
      "ID": "MoveOldLogsToGlacier",
      "Status": "Enabled",
      "Filter": { "Prefix": "logs/" },
      "Transitions": [
        { "Days": 30, "StorageClass": "STANDARD_IA" },
        { "Days": 90, "StorageClass": "GLACIER" }
      ],
      "Expiration": { "Days": 2555 }  // 7 years retention
    }
  ]
}

# Database: Use read replicas for read-heavy workloads
# Instead of scaling primary DB vertically ($$$), add read replicas ($)

Step 5: Reserved Capacity and Commitments

RESERVED CAPACITY DECISION MATRIX:

Usage Pattern          → Recommendation
─────────────────────────────────────────────────
24/7 steady state      → 1-year reserved (40-60% savings)
Predictable growth     → 3-year reserved (up to 70% savings)
Seasonal / burst       → Savings plans (flexible commitment)
Unpredictable / dev    → Stay on-demand (flexibility > savings)
Spot-capable workloads → Spot instances (up to 90% savings)

Spot / preemptible instance strategy:

// Stateful workloads: Use spot with fallback
const computeStrategy = {
  primary: 'spot',           // 90% cheaper
  fallback: 'on-demand',     // When spot is unavailable
  maxSpotPrice: 0.50,        // Don't pay more than 50% of on-demand
  interruptionBehavior: 'stop', // Save state, resume later
};

// Stateless workloads: Pure spot with auto-scaling
const workerPool = {
  instanceType: 'c5.xlarge',
  capacity: 'spot-only',
  minSize: 2,
  maxSize: 50,
  targetCPU: 70,
};

Step 6: Implement and Monitor

Every optimization must be measurable:

## Optimization: [Name]

### Baseline
- Monthly cost: $[X]
- Primary driver: [compute/storage/network]
- Waste identified: [specific resources]

### Changes Made
1. [Change 1 with justification]
2. [Change 2 with justification]

### Results
- New monthly cost: $[Y] ([Z]% reduction)
- Performance impact: [none / improved / degraded — quantify]
- Reliability impact: [none / improved / degraded — quantify]

### Ongoing Monitoring
- Alert if cost exceeds $[threshold]
- Review monthly on [date]
- Re-evaluate if traffic changes > 20%

Architecture Patterns for Cost Efficiency

Design for Scale-to-Zero

// Serverless functions for intermittent workloads
// Pay only for invocations, not idle time
export async function processWebhook(event: APIGatewayEvent) {
  // Cold start: ~200ms (acceptable for async processing)
  // Runtime: $0.20 per million requests vs $72/month for smallest VM
  await validateWebhook(event);
  await enqueueForProcessing(event.body);
  return { statusCode: 202 };
}

Caching to Reduce Compute

CACHE HIERARCHY (cheapest to most expensive):
1. Browser cache (free for you)
2. CDN edge cache (pennies per GB)
3. Application cache (memory — cheap but limited)
4. Database cache (query cache, materialized views)
5. Re-compute (most expensive)

Data Transfer Minimization

# BAD: Client → API → Database → API → Client (4 hops)
# GOOD: Client → CDN (cache hit) — 1 hop, $0.01/GB

# BAD: Cross-region replication for all data
# GOOD: Replicate metadata only, fetch data on-demand

# BAD: NAT Gateway for all outbound traffic ($0.045/GB)
# GOOD: VPC endpoints for AWS services ($0/GB)

Common Rationalizations

RationalizationReality
"We're too small for cost optimization to matter"A single oversized database or forgotten dev environment can cost $500+/month. That's $6K/year — enough for a junior engineer's salary in many markets.
"Optimization will hurt performance"Proper optimization improves performance. Rightsizing forces you to fix inefficiencies. Caching reduces latency.
"We'll just scale vertically"Vertical scaling is the most expensive option. Horizontal scaling with smaller instances + auto-scaling is cheaper and more resilient.
"Reserved capacity locks us in"Savings plans and convertible reserved instances provide flexibility. The "lock-in" cost is usually < 10% of the savings.
"Engineer time is more expensive than cloud costs"True for small optimizations, but a single rightsizing exercise can save $10K+/year — that's more than the engineering time spent.

Red Flags

  • Cloud bill is reviewed only when finance complains
  • No tagging strategy (can't allocate costs to teams/products)
  • "We'll optimize later" — later never comes
  • All environments run 24/7 (dev/staging should auto-shutdown)
  • Using latest instance types without comparing price/performance
  • Data transfer costs > 15% of total bill
  • No auto-scaling (manually sized for peak, paying for peak 24/7)

Verification

After optimization:

  • Costs reduced by target amount (quantified)
  • Performance metrics unchanged or improved
  • Reliability metrics unchanged or improved
  • Monitoring and alerts updated for new baseline
  • Team trained on new cost-aware practices
  • Review scheduled (monthly for first 3 months, then quarterly)

See Also

  • For performance optimization alongside cost work, see performance-optimization
  • For infrastructure decisions, see observability-and-instrumentation (you need metrics to optimize)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.