Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 38 ยท Snowpark and Cost

Cost Monitoring and Resource Monitors

Understand Snowflake billing for compute, storage and serverless features, find the expensive warehouses and queries, and set resource monitors and budgets that cap spend.

Snowflake makes it easy to start work and just as easy to forget what it costs. Because you pay for use, a forgotten warehouse, a runaway query or a too-aggressive refresh shows up on the invoice. Cost control is a skill with three parts: know what you are billed for, see where the credits go, and put guardrails in place.

Billing data exists only in a real account. The queries against ACCOUNT_USAGE are read-only; the runnable examples use small invented usage tables so you can practice the analysis in SQL and Python.

What Snowflake bills

Category Charged by Examples
Compute: virtual warehouses Credits per second while running (60 s minimum per start) Queries, loads, tasks on warehouses
Compute: serverless Credits for compute Snowflake manages Snowpipe, Automatic Clustering, search optimization, materialized views, serverless tasks, query acceleration
Cloud services Credits, but only the part above 10% of daily warehouse credits Metadata, authentication, query compilation
Storage Per terabyte per month on compressed data Tables, Time Travel history, fail-safe, stages
Data transfer Per terabyte for egress to another region or cloud Cross-region sharing, unloading

A credit's price depends on your edition (Standard, Enterprise, Business Critical), cloud and region, and on whether you buy on demand or pre-pay a capacity contract. Storage is cheaper per TB than compute is per credit, so the usual cost problem is compute.

Storage grows less obviously: each change keeps old versions for Time Travel (default 1 day, up to 90 days on Enterprise) and fail-safe (7 more days). Large tables that change often, or transient staging data, can silently multiply storage. Use transient tables (no fail-safe) and short retention for staging data.

Where did the credits go?

Two schemas answer cost questions. SNOWFLAKE.ACCOUNT_USAGE has a long history (a year) but data can lag by up to a few hours; INFORMATION_SCHEMA is near real time but short-lived.

SQL
-- Credits per warehouse over the last 30 days
SELECT warehouse_name,
       SUM(credits_used)               AS credits,
       SUM(credits_used_compute)       AS compute,
       SUM(credits_used_cloud_services) AS cloud_services
FROM snowflake.account_usage.warehouse_metering_history
WHERE start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP())
GROUP BY warehouse_name
ORDER BY credits DESC;

-- Most expensive queries by time spent
SELECT query_id, user_name, warehouse_name, warehouse_size,
       total_elapsed_time / 1000 AS seconds,
       bytes_scanned / POWER(1024, 3) AS gb_scanned
FROM snowflake.account_usage.query_history
WHERE start_time >= DATEADD('day', -7, CURRENT_TIMESTAMP())
ORDER BY total_elapsed_time DESC
LIMIT 20;

-- Overall usage by service type
SELECT service_type, SUM(credits_used) AS credits
FROM snowflake.account_usage.metering_history
WHERE start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP())
GROUP BY service_type
ORDER BY credits DESC;

The same analysis can be practiced on a pretend metering table:

SQL Which warehouse costs the most? (stand-in data) ยท database: company

Press Run (or Ctrl + Enter) to see the result here.

The second query flags 2025-03-03 for ETL_WH: a spike worth investigating (a runaway job or a changed query). This is the style of check you would schedule as an alert.

Resource monitors

A resource monitor counts the credits used by warehouses (or the whole account) in a period and triggers actions at thresholds. It is the hard guardrail.

SQL
CREATE RESOURCE MONITOR etl_monthly
  WITH CREDIT_QUOTA = 1000
       FREQUENCY = MONTHLY
       START_TIMESTAMP = IMMEDIATELY
  TRIGGERS ON 75  PERCENT DO NOTIFY
           ON 90  PERCENT DO NOTIFY
           ON 100 PERCENT DO SUSPEND
           ON 110 PERCENT DO SUSPEND_IMMEDIATE;

ALTER WAREHOUSE etl_wh SET RESOURCE_MONITOR = etl_monthly;
-- or the whole account:
ALTER ACCOUNT SET RESOURCE_MONITOR = account_guard;
  • NOTIFY emails account administrators who enabled notifications.
  • SUSPEND lets running queries finish, then suspends the warehouse.
  • SUSPEND_IMMEDIATE cancels running queries and suspends at once.
  • Monitors apply to warehouse credits only. Serverless features are not stopped by resource monitors; use budgets for those.
Python Triggers at thresholds (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The notifications give early warning; the suspend threshold is the stop. Without it, a bad job could burn the entire month's budget overnight.

Budgets and tags

Budgets track spend (including serverless features) against a monthly credit limit for a group of objects and send alerts to email, queues or webhooks. Use object tags (for example cost_center = 'marketing') on warehouses, and attribute usage per team with TAG_REFERENCES and WAREHOUSE_METERING_HISTORY. Aim for one warehouse per workload and per team, so the cost of each is visible.

Ten savings habits

  1. Auto-suspend every warehouse (60 seconds for batch, a few minutes for BI).
  2. Start small; resize only when the Query Profile shows spilling or long runs.
  3. Separate workloads; use multi-cluster scale-out only where concurrency demands it.
  4. Fix scans first: pruning, clustering where justified, fewer columns, LIMIT during exploration.
  5. Reuse results: identical dashboard queries hit the result cache.
  6. Lengthen dynamic-table lag and task schedules to what the business really needs.
  7. Use transient tables, short retention and cleanup for staging data; drop unused clones.
  8. Put statement time limits in place (STATEMENT_TIMEOUT_IN_SECONDS) so runaway queries stop.
  9. Review serverless costs (clustering, search optimization, materialized views) monthly.
  10. Add resource monitors and budgets before you need them.
SQL
ALTER WAREHOUSE bi_wh SET STATEMENT_TIMEOUT_IN_SECONDS = 3600;
ALTER WAREHOUSE bi_wh SET AUTO_SUSPEND = 120;

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which charges are NOT stopped by a resource monitor on a warehouse?

    Resource monitors cover warehouse credits; serverless usage is tracked with budgets.
  2. 2. What does a SUSPEND trigger at 100% do?

    SUSPEND waits for current queries; SUSPEND_IMMEDIATE cancels them.
  3. 3. Which view lists credits used per warehouse over time?

    WAREHOUSE_METERING_HISTORY records credits used by each warehouse per hour.
  4. 4. Why can storage costs grow even when data volume looks stable?

    Historical versions are retained for Time Travel and fail-safe, and are billed as storage.
  5. 5. A good first step to cut the cost of a rarely used warehouse is...

    A short auto-suspend stops billing when the warehouse is idle.

Summary

  • Compute dominates: warehouses (per second), serverless features, cloud services above 10%; storage includes Time Travel and fail-safe.
  • Use ACCOUNT_USAGE views to find costly warehouses and queries.
  • Resource monitors notify and suspend warehouses; budgets cover serverless usage.
  • Auto-suspend, right-size, separate workloads, fix scans and set timeouts.

Next: Project: a retail analytics pipeline