ivanshamaev/de-agent-skills/de-cost-optimization
Claude Code and agent skill by ivanshamaev/de-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
DE cost optimization — query cost analysis (Trino/Spark/ClickHouse/BigQuery), compute right-sizing, storage tier recommendations, spot/preemptible instances, partition pruning, Z-order/clustering, materialized view economics, data lifecycle policies, FinOps tagging, cost attribution, budget alerts
Install
npx vskill@latest install ivanshamaev/de-agent-skills/de-cost-optimizationSKILL.md
The same SKILL.md was published earlier as ivanshamaev/de-agent-skills/de-cost-optimization.
DE Cost Optimization
When to Use
Load this skill when the user needs to:
- Review a cloud bill and identify which pipelines, queries, or clusters drive cost
- Right-size a Spark, Trino, ClickHouse, or Airflow cluster (instance type, memory, core count)
- Reduce query scan costs via partition pruning, Z-order clustering, or file compaction
- Move data to cheaper storage tiers (S3-IA, Glacier, ClickHouse cold volumes)
- Implement spot/preemptible instances for Spark executors or Airflow workers
- Decide whether to materialize a view or a summary table (refresh cost vs query savings)
- Define or enforce a data lifecycle and retention policy
- Set up AWS/GCP budget alerts, FinOps tagging, or per-team cost attribution
- Run a FinOps review and produce a prioritized cost reduction plan
1. Cost Model Overview
Every data engineering cloud bill breaks down into three levers. Attack them in this order — storage is cheapest per GB, but compute at scale dominates the total.
| Lever | Driver | Typical Share | First Action | |
|---|---|---|---|---|
| Compute | vCPU-hours × instance price | 50-70% | Right-size + spot instances | |
| Storage | GB-months × tier price | 20-35% | Tiering + compaction + lifecycle rules | |
| Data transfer | GB egressed across AZs/regions | 5-15% | Co-locate compute with storage; avoid cross-region reads |
How Each Scales
- Compute scales with cluster lifetime × size. A cluster that is 2× over-provisioned and never auto-scales burns double money even when idle. Idle Spark clusters during off-peak hours are the single most common waste category.
- Storage scales with raw data volume × replication factor × tier. Columnar + compressed formats (Parquet/zstd) reduce this 5-10× vs raw JSON/CSV.
- Data transfer is often invisible until bill arrives. Reading Parquet on S3 from a same-region EMR cluster is free; reading it cross-region costs $0.02/GB and can exceed compute cost on large jobs.
Which to Attack First
2. Query Cost Analysis
2.1 Trino / Presto
Reading EXPLAIN (TYPE DISTRIBUTED)
Key tokens to look for in the output:
| Token | Meaning | Cost Signal | |
|---|---|---|---|
TableScan | Rows and bytes read from storage | High bytes → missing partition filter | |
Filter | Pushed down to connector vs applied in Trino | filterPushdown=false → scan waste | |
RemoteExchange REPARTITION | Network shuffle | Many reshuffles → expensive join | |
Estimates: {rows=..., cpu=..., network=..., memory=...} | Planner estimates | Cross-check with actual |
Partition filter pushdown is confirmed when the TableScan node shows partitionedBy columns in its predicate. If your WHERE order_date = ... clause does NOT appear in the TableScan predicate, it means the filter is not pushed down — you are scanning the whole table and filtering in memory.
Finding Expensive Queries via system tables
File Size Optimization
- Too-small files (<10 MB): excessive S3 LIST + GET overhead; Trino opens one reader thread per file, so 10,000 files × overhead > reading one 1 GB file.
- Too-large files (>1 GB): cannot be split across workers in parallel; one task processes the whole file.
- Sweet spot: 128–512 MB per file after compression.
2.2 Spark (EMR / Databricks / Self-Hosted)
Spark UI Cost Signals
Navigate: Jobs → select expensive job → Stages → sort by Duration descending.
Key indicators:
- Shuffle Read/Write size: A stage with 500 GB shuffle write followed by a stage with 500 GB shuffle read means you are moving 500 GB over the network. Each GB shuffled costs executor CPU time + network I/O + potential spill to disk.
- GC time % > 10%: executors spending >10% in garbage collection → memory is too low for the data size; increase
spark.executor.memoryor reduce partition size. - Task skew: longest task 10× median → one partition is much larger than others (data skew). Fix with salting or AQE.
- Spill (Memory) / Spill (Disk): non-zero spill means tasks ran out of memory and wrote to disk → slower and wastes I/O.
EXPLAIN COST
Look for Statistics(sizeInBytes=..., rowCount=...). If estimates are wildly wrong, run ANALYZE TABLE orders COMPUTE STATISTICS FOR ALL COLUMNS to refresh them — bad statistics cause the planner to choose wrong join strategies (BroadcastHashJoin vs SortMergeJoin).
Executor Sizing Formula
Dynamic Allocation vs Fixed: Cost Comparison
Reading EMR Utilization from CloudWatch
2.3 ClickHouse
Identifying Expensive Queries
Verifying Projection Usage
Cold vs Hot Data Cost Model (TTL MOVE)
2.4 BigQuery
Finding Expensive Queries
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/de_cost_optimization/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ivanshamaev/de-agent-skills/de-cost-optimization)