Database / Snowflake Interview Questions
What are Snowflake Tasks and how do you schedule SQL transformations with them?
A Task is a named Snowflake object that executes a single SQL statement (or a stored procedure call) on a defined schedule. Tasks are the native scheduling mechanism for data transformations inside Snowflake — no external orchestration tool is required for pipelines that can be expressed as SQL.
Schedule options: SCHEDULE = '5 MINUTE' runs the task every 5 minutes. SCHEDULE = 'USING CRON 0 6 * * MON-FRI America/New_York' uses standard cron syntax with a timezone. Tasks default to a user-specified warehouse, but serverless tasks (no warehouse needed) are also supported and billed by compute seconds.
Task DAGs: a root task holds the schedule; child tasks use AFTER <parent_task> to declare dependencies. When the root fires, Snowflake runs the tree in dependency order, fan-out and fan-in patterns included. Tasks are created in SUSPENDED state and must be activated with ALTER TASK ... RESUME.
Combining Streams and Tasks is the idiomatic CDC pipeline: the task body checks SYSTEM$STREAM_HAS_DATA('stream_name') and only proceeds when new changes exist, avoiding empty executions.
-- Root task: runs every 10 minutes on the transform warehouse
CREATE TASK load_staging
WAREHOUSE = transform_wh
SCHEDULE = '10 MINUTE'
AS
CALL load_staging_proc();
-- Child task: runs after load_staging completes
CREATE TASK build_aggregates
WAREHOUSE = transform_wh
AFTER load_staging
AS
INSERT INTO daily_summary SELECT ...;
-- Both tasks must be resumed before they will fire
ALTER TASK build_aggregates RESUME;
ALTER TASK load_staging RESUME;
More Related questions...