Schedule icon
Query icon
Script icon
Process icon
If icon
SlackIncomingWebhook icon

Snowflake Query Spill and Warehouse Rightsizing Advisor

Audit Snowflake QUERY_HISTORY for memory spill to local and remote storage. Detect undersized warehouses and generate optimization guidance.

Categories
BusinessData

In Snowflake, when a query's working memory requirements exceed available server RAM, the query execution engine spills intermediate partitions first to local SSD storage, and if that is exhausted, to remote cloud object storage (such as AWS S3, Google Cloud Storage, or Azure Blob Storage).

While local disk spill introduces minor I/O overhead, remote storage spill causes catastrophic performance degradation: queries that normally take seconds can stretch into hours as worker nodes wait on synchronous network I/O to transfer spilled intermediate tables. Furthermore, because Snowflake warehouses bill by compute cluster uptime per second, long-running spilled queries drastically inflate end-of-month cloud bills.

This blueprint provides automated, non-invasive query performance and FinOps governance for Snowflake. It periodically inspects SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY, identifies queries with remote storage spills, aggregates spill metrics by warehouse and user, generates an executive markdown remediation brief, and dispatches an actionable Slack notification with warehouse rightsizing recommendations.

How it works

  1. query_spilled_workloads (jdbc.snowflake.Query): Connects to Snowflake ACCOUNT_USAGE and extracts queries from the configured lookback window where BYTES_SPILLED_TO_REMOTE_STORAGE exceeds the configured threshold or BYTES_SPILLED_TO_LOCAL_STORAGE exceeds 10 GB.
  2. generate_spill_optimization_report (scripts.python.Script): Aggregates total remote and local spill volumes across all flagged queries, groups metrics by warehouse size, and outputs snowflake-query-spill-remediation-report.md.
  3. evaluate_spill_severity (core.flow.If): Evaluates whether spilled workloads were detected. If true, dispatches a rich alert card to the configured Slack channel.
  4. alert_on_failure (errors block): Catches unexpected connection or execution errors and notifies the DataOps team.

What you get

  • Early detection of memory-starved warehouses before query timeouts disrupt downstream BI reporting.
  • Clear distinction between tolerable local SSD spill and high-severity remote cloud storage spill.
  • Automated warehouse rightsizing guidance (e.g. recommending scaling from Medium to Large to double per-node memory).
  • Persistent execution artifacts detailing the top spilling query IDs, users, and SQL excerpts.

Who it's for

  • Data Platform Engineers and Snowflake Administrators managing multi-tenant warehouses.
  • Analytics Engineers debugging slow dbt models or runaway transformation jobs.
  • FinOps Practitioners optimizing cloud data warehouse credit consumption.

Why orchestrate this with Kestra

Snowflake resource monitors only support crude credit quotas that abruptly suspend running warehouses, risking corruption or aborting critical business operations. Kestra delivers declarative, diagnostic automation: it detects the specific queries causing the spill, surfaces actionable root cause data, and enables proactive rightsizing without disrupting production workloads.

Prerequisites

  • Snowflake account with access to the SNOWFLAKE.ACCOUNT_USAGE shared database (typically granted to ACCOUNTADMIN or custom governance roles).
  • Slack incoming webhook endpoint for DataOps notifications.

Secrets

  • SNOWFLAKE_ACCOUNT: Snowflake account identifier (e.g. xy12345.us-east-1).
  • SNOWFLAKE_USER: Service account username.
  • SNOWFLAKE_PASSWORD: Service account authentication password.
  • SNOWFLAKE_WAREHOUSE: Warehouse used to run the diagnostic query.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL.

Quick start

  1. Configure your Snowflake credentials and Slack webhook URL in your Kestra namespace secrets.
  2. Click Execute in the Kestra UI with lookback_hours set to 24.
  3. Download snowflake-query-spill-remediation-report.md from the Outputs tab to review flagged queries.

How to extend

  • Add an automated ALTER WAREHOUSE <name> SET WAREHOUSE_SIZE = '...' task inside Kestra to automatically scale up undersized warehouses during heavy batch windows.
  • Push query spill metrics to Datadog or Prometheus using Kestra metric push plugins.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.