Snowflake Cost Optimization: Mastering Credits, Warehouses, and Storage
Learn to optimize Snowflake costs by managing credits, virtual warehouses, and storage.
20+ years shipping high-throughput database systems. Notes here come from systems that actually shipped.
- ✓Basic understanding of Snowflake architecture (warehouses, databases, schemas).
- ✓Access to Snowflake account with ACCOUNTADMIN or MONITOR privileges.
- ✓Familiarity with SQL queries and Snowflake's INFORMATION_SCHEMA.
- Use auto-suspend and auto-resume to avoid paying for idle warehouses.
- Right-size warehouses by matching size to workload concurrency and complexity.
- Leverage clustering keys and materialized views to reduce scanned data.
- Monitor storage costs by compressing and removing stale data.
- Set resource monitors and budgets to prevent runaway spending.
Think of Snowflake like a cloud kitchen: you pay for the ingredients (storage) and the chef's time (compute). If you leave the chef idle, you still pay. So you want the chef to start cooking only when orders come in (auto-resume) and leave when done (auto-suspend). Also, you don't need a 5-star chef for simple tasks like boiling water (right-size warehouse). And you should organize your pantry (clustering) to find ingredients faster, reducing chef time.
| Chrome | Firefox | Safari | Edge |
|---|---|---|---|
| ✓ | ✓ | ✓ | ✓ |
Snowflake's pay-as-you-go model is a double-edged sword: it offers elasticity and no upfront costs, but without careful management, your monthly bill can skyrocket. Credits are consumed by virtual warehouses (compute) and storage. Many teams unknowingly waste credits on oversized warehouses, idle compute, or inefficient queries. This tutorial dives deep into cost optimization strategies, from warehouse configuration to storage lifecycle management. You'll learn how to monitor usage, set resource monitors, and implement best practices that can cut costs by 30-50%. We'll also explore a real production incident where a misconfigured warehouse caused a $10k overnight spike. By the end, you'll be equipped to optimize Snowflake costs without sacrificing performance.
This tutorial aligns with the SnowPro Core certification objectives, helping you prepare for the SnowPro exam while building practical skills.
Understanding Snowflake's Pricing Model
Snowflake charges for compute (credits) and storage separately. Compute is consumed by virtual warehouses, which are clusters of compute resources. Storage costs are based on compressed data stored in Snowflake's cloud storage. Additionally, there are costs for cloud services (e.g., metadata operations) but these are usually minimal. Credits are billed per second, with a minimum of 60 seconds per warehouse start. The cost per credit varies by cloud provider and region. For example, on AWS US East, 1 credit = $2.00 (on-demand). Storage costs are typically $23 per terabyte per month (compressed). Understanding these components is the first step to optimization.
Right-Sizing Virtual Warehouses
Choosing the right warehouse size is critical. A common mistake is using a large warehouse for small queries, wasting credits. Use the following guidelines: For simple queries (e.g., point lookups), X-Small or Small is sufficient. For complex aggregations or joins on large tables, consider Medium or Large. For very large data loads or complex ETL, use X-Large or larger. Monitor warehouse load using the WAREHOUSE_LOAD_HISTORY view. If a warehouse is less than 50% utilized, consider downsizing. Also, use multi-cluster warehouses only when concurrency demands it; each additional cluster doubles credit consumption.
Auto-Suspend and Auto-Resume Best Practices
Auto-suspend stops a warehouse after a specified period of inactivity, saving credits. Auto-resume starts it automatically when a query is submitted. Set auto_suspend to 5-10 minutes for most warehouses. For development or ad-hoc warehouses, 1 minute is fine. For production warehouses that need to be always available, you might set it longer (e.g., 30 minutes) but be aware of the cost. Never set auto_suspend to NULL (never suspend) unless you have a specific reason. Also, ensure auto_resume is set to TRUE so that the warehouse starts on demand.
Using Resource Monitors to Cap Spending
Resource monitors allow you to set credit limits on warehouses or the entire account. You can define actions when a limit is reached: notify, suspend, or abort queries. Create separate monitors for different warehouses or groups. For example, set a monthly limit of 1000 credits for the BI warehouse, with an alert at 80% and suspend at 100%. This prevents surprise bills. Resource monitors can be set at the account level or warehouse level.
Optimizing Storage Costs
Storage costs are based on compressed data. Snowflake automatically compresses data, but you can reduce storage by: 1) Dropping unused tables and schemas. 2) Reducing Time Travel retention (default 1 day, max 90 days). Each day of Time Travel adds to storage. 3) Using clustering keys to improve compression and query performance. 4) Archiving old data to cheaper storage (e.g., S3 Glacier). Monitor storage with TABLE_STORAGE_METRICS and STAGE_STORAGE_USAGE_HISTORY.
Query Optimization to Reduce Compute
Inefficient queries waste credits. Use clustering keys to minimize data scanned. For large tables, define clustering keys on columns used in filters (e.g., date). Also use materialized views for pre-aggregated results. Avoid SELECT *; only select needed columns. Use query profiling (EXPLAIN) to identify full scans or large joins. Set up automatic clustering for tables that benefit from it. Monitor query performance with QUERY_HISTORY.
Monitoring and Alerting with Account Usage Views
Snowflake provides rich account usage views in the SNOWFLAKE database. Key views: WAREHOUSE_METERING_HISTORY (credit consumption), QUERY_HISTORY (query performance), TABLE_STORAGE_METRICS (storage), and RESOURCE_MONITORS (monitor status). Set up regular queries to generate cost reports. You can also use Snowsight dashboards to visualize usage. Consider setting up alerts for unusual spikes using tasks or external tools.
The $10k Overnight Warehouse Spiral
- Always set auto_suspend on every warehouse, especially for ad-hoc or temporary workloads.
- Use resource monitors to cap credit usage and send alerts.
- Regularly audit warehouse configurations with SHOW WAREHOUSES.
- Implement a process to review and clean up unused warehouses.
- Enable auto-resume to avoid manual start/stop.
SELECT WAREHOUSE_NAME, SUM(CREDITS_USED) FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME > DATEADD('day', -7, CURRENT_TIMESTAMP) GROUP BY 1 ORDER BY 2 DESC;SHOW WAREHOUSES;| File | Command / Code | Purpose |
|---|---|---|
| warehouse_load.sql | SELECT WAREHOUSE_NAME, | Right-Sizing Virtual Warehouses |
| alter_warehouse.sql | ALTER WAREHOUSE my_wh SET | Auto-Suspend and Auto-Resume Best Practices |
| create_resource_monitor.sql | CREATE RESOURCE MONITOR my_monitor | Using Resource Monitors to Cap Spending |
| storage_metrics.sql | SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, | Optimizing Storage Costs |
| clustering_example.sql | ALTER TABLE sales CLUSTER BY (sale_date); | Query Optimization to Reduce Compute |
| cost_report.sql | SELECT DATE(START_TIME) AS day, | Monitoring and Alerting with Account Usage Views |
Key takeaways
Common mistakes to avoid
3 patternsSetting auto_suspend to NULL or 0
Using a single large warehouse for all queries
Not using resource monitors
Interview Questions on This Topic
Explain how Snowflake's pricing model works.
Frequently Asked Questions
20+ years shipping high-throughput database systems. Notes here come from systems that actually shipped.
That's Snowflake. Mark it forged?
3 min read · try the examples if you haven't