❄️
Data Flakes

Back

In this article let’s dive into Snowflake Tasks, what they are, how they work, how to implement them, and best practices to get the most out of your automation efforts.

Features change from time to time with new features being added regularly, it is recommended that you review the documentation for the latest on what specific features are included with any of the Editions.

What Are Snowflake Tasks?#

At a fundamental level, a Snowflake Task is a scheduled or event-driven object that executes a single SQL statement or a stored procedure. Tasks are used to automate business processes, maintain data freshness, and support data transformation pipelines.

Tasks can:

  • Be scheduled using CRON syntax.
  • Be triggered by the completion of other tasks (task graphs).
  • React to changes in data using Snowflake Streams.
  • Execute with either serverless compute or user-managed warehouses.

Why Use Snowflake Tasks?#

Snowflake Tasks reduce operational overhead by automating routine data operations.

They are a key enabler for:

  • Periodic transformations (daily aggregations, table maintenance).
  • Real-time or near real-time processing (using Streams and triggered Tasks).
  • Creating Directed Acyclic Graphs (DAGs) for dependent task orchestration.

Task Execution Models#

Serverless Tasks#

With serverless tasks, Snowflake provisions and manages compute resources automatically. You don’t need to specify a warehouse.

Benefits:#

  • Auto-scaling compute.
  • Cost-effective for infrequent or short-running jobs.
  • Ideal for triggered workflows.

Limitations:#

  • Maximum size equivalent to XXLARGE warehouse.
  • Slight delay in execution due to provisioning.

Below is an example of how a serverless task can be created in Snowflake:

CREATE TASK my_serverless_task
  SCHEDULE = 'USING CRON 0 * * * * UTC'
  TARGET_COMPLETION_INTERVAL = '10 MINUTE'
  AS
  CALL process_hourly_data();
sql

User-Managed Tasks#

These tasks specify a virtual warehouse for execution. They offer more control and are suitable for predictable workloads.

CREATE TASK my_manual_task
  WAREHOUSE = my_wh
  SCHEDULE = 'USING CRON 0 0 * * * UTC'
  AS
  CALL process_daily_aggregates();
sql

Task Graphs (DAGs)#

Task graphs define parent-child relationships, ensuring proper execution order. These are essential for complex workflows like:

Data ingestion → 2. Data transformation → 3. Report generation

CREATE TASK stage_1
  SCHEDULE = '1 HOUR'
  AS
  CALL ingest_data();

CREATE TASK stage_2
  AFTER stage_1
  AS
  CALL transform_data();

CREATE TASK stage_3
  AFTER stage_2
  AS
  CALL generate_reports();
sql

Task Triggers Using Streams#

For reactive processing, combine tasks with Streams:

  • Monitor new/updated data.
  • Trigger tasks only when data changes.
  • Ideal for event-driven architecture.
CREATE TASK process_stream
  AFTER insert_stream
  WHEN
    SYSTEM$STREAM_HAS_DATA('my_stream')
  AS
  CALL process_new_data();
sql

Best Practices#

When implementing Snowflake Tasks, consider these recommendations:

  • Start Simple: Begin with a single task before building complex DAGs.
  • Use Serverless for Variable Workloads: Serverless tasks auto-scale and avoid warehouse idle costs.
  • Monitor Task History: Query TASK_HISTORY in ACCOUNT_USAGE to track execution patterns and failures.
  • Set Appropriate Timeouts: Configure USER_TASK_TIMEOUT_MS to prevent runaway tasks.
  • Leverage SYSTEM$STREAM_HAS_DATA: Only run tasks when there’s actual data to process.
  • Name Tasks Descriptively: Use clear naming conventions that indicate purpose and order.

When to Use Tasks: Decision Guide#

ScenarioUse TasksAlternative
Scheduled ETL/ELT transformations-
Real-time CDC processing with Streams-
Complex multi-step pipelines✅ (DAGs)External orchestrators
Sub-minute scheduling requirementsSnowpipe Streaming
Cross-cloud orchestrationAirflow, Dagster
Heavy external API dependenciesExternal orchestrators

Conclusion#

Snowflake Tasks offer a powerful and flexible way to automate workflows within your data platform. Whether you’re running scheduled maintenance jobs, orchestrating multi-step pipelines, or processing real-time data changes, tasks provide the backbone for building efficient, scalable, and manageable solutions.

To get started:

  • Try creating a basic task using the CREATE TASK syntax.
  • Explore DAGs for multi-stage workflows.
  • Combine with Streams for reactive ELT pipelines.

Snowflake Tasks are more than just schedulers—they’re automation tools built for the modern data cloud.

Features change from time to time with new features being added regularly, it is recommended that you review the documentation for the latest on what specific features are included with any of the Editions.

Sources#

Disclaimer

The information provided on this website is for general informational purposes only. While we strive to keep the information up to date and correct, there may be instances where information is outdated or links are no longer valid. We make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability, or availability with respect to the website or the information, products, services, or related graphics contained on the website for any purpose. Any reliance you place on such information is therefore strictly at your own risk.