FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Guides

Are Dynamic Tables worth it? Build the same Snowflake pipeline twice

With incremental refresh, cost follows how fast data changes rather than table size, and building the pipeline both ways shows what each approach leaves you to manage.

Snowflake's booth at a technology conference, with the Snowflake logo and the slogan "Mobilizing the World's Data," as staff talk with visitors.
Photo: Raysonho @ Open Grid Scheduler / Scalable Grid Engine / CC0
ShareLinkedInFacebookX

In brief

  • A dynamic table stores the result of a SELECT as a table and keeps it up to date on its own. In INCREMENTAL mode, each refresh processes only the rows that changed.
  • Streams and Tasks give you full control, but you have to handle offsets, scheduling, MERGE and stale streams yourself.
  • Snowflake recommends dynamic tables for new SQL pipelines. Switch to streams and tasks only when you need MERGE, stored procedures or external function calls.
Decision tree: if a pipeline needs an external function, a stored procedure or its own MERGE logic, choose Streams and Tasks, which means four objects and a hand-written MERGE, with alerts for suspended tasks and stale streams. If not, choose a dynamic table, which takes a single SELECT statement.
For new SQL pipelines, prefer dynamic tables. Choose streams and tasks only when you need stored procedures, a custom MERGE, external functions, or full control over incremental processing. In that case, build task state and stream staleness into alerting from day one. Source: Snowflake decision guide; Snowflake's 2022 blog post introducing Dynamic Tables.

Snowflake’s decision guide says a dynamic table folds four objects and all of the MERGE logic into a single SELECT definition. That sounds like marketing copy. The best way to test the claim is to build the same pipeline both ways and compare what each one leaves you to worry about.

For FDEs this is a familiar situation. A client has an orders table that grows every hour and a revenue dashboard that is recomputed from scratch every night. They want fresher numbers without a bigger compute bill. By the end of this guide you will have two versions of that pipeline and know which one to recommend.

What you need: a Snowflake account with permission to create tables, streams, tasks and dynamic tables; a small warehouse (called transform_wh here); and a source table raw_orders with the columns store_id, order_ts and amount. The scenario is hypothetical, and the code has been trimmed to keep it easy to follow.

Why does “incremental” decide the cost?

When Snowflake introduced Dynamic Tables in 2022, it described incremental processing as the hardest challenge. The reason: with incremental refresh, cost scales with how fast the input data changes, not with the size of the table.

Take a table with 10 million rows that gains 20,000 rows an hour. A full recompute reads 10 million rows on every run. An incremental refresh processes only the roughly 20,000 new rows each time. Ask the client for this number in your first working session.

Step 1: one SELECT, one dynamic table

According to Snowflake’s documentation, a dynamic table stores the result of a SELECT as a table and keeps that result up to date automatically. TARGET_LAG is the maximum amount of time the table’s contents may trail the source table. WAREHOUSE is the warehouse that runs the refreshes.

CREATE OR REPLACE DYNAMIC TABLE daily_revenue
  TARGET_LAG = '5 minutes'
  WAREHOUSE = transform_wh
  REFRESH_MODE = INCREMENTAL
AS
SELECT store_id,
       DATE(order_ts) AS order_date,
       SUM(amount)    AS revenue,
       COUNT(*)       AS orders
FROM raw_orders
GROUP BY store_id, DATE(order_ts);

There are three refresh modes. INCREMENTAL processes only the rows that changed since the previous refresh. FULL recomputes everything. In AUTO mode, the system tries incremental refresh by default. The example above spells out INCREMENTAL so it is obvious what you are choosing. To let the system decide, switch to AUTO.

How to check: insert a few rows into raw_orders, wait for the TARGET_LAG window to pass, then SELECT from daily_revenue. Revenue for the relevant store should go up without you running any other command.

TARGET_LAG also accepts a second value, DOWNSTREAM, which becomes useful once other dynamic tables read from daily_revenue. Before using it on a client’s chain of tables, read carefully how it works in the CREATE DYNAMIC TABLE documentation.

Step 2: rebuild it by hand with a stream

Now rebuild exactly the same logic without a dynamic table. A stream records DML changes on the source table from an offset.

CREATE OR REPLACE STREAM raw_orders_stream ON TABLE raw_orders;

CREATE OR REPLACE TABLE daily_revenue_manual (
  store_id INT, order_date DATE, revenue NUMBER, orders INT
);

How to check, and the first trap: insert three rows into raw_orders, then run SELECT * FROM raw_orders_stream twice in a row. Both times you get the same three rows, because querying a stream does not move its offset. The offset advances only when the stream is used in a DML transaction, such as a MERGE or an INSERT.

Newcomers often assume they have “consumed” the stream because they ran a SELECT. In fact the data is still there, waiting for a DML statement to consume it.

Step 3: a task and a MERGE

A task can run on a schedule or be triggered by an event, for example when a stream has new data. This example combines both: the task is scheduled every 5 minutes but only actually runs when SYSTEM$STREAM_HAS_DATA returns true.

CREATE OR REPLACE TASK merge_daily_revenue
  WAREHOUSE = transform_wh
  SCHEDULE = '5 MINUTE'
  WHEN SYSTEM$STREAM_HAS_DATA('raw_orders_stream')
AS
MERGE INTO daily_revenue_manual t
USING (
  SELECT store_id, DATE(order_ts) AS order_date,
         SUM(amount) AS revenue, COUNT(*) AS orders
  FROM raw_orders_stream
  GROUP BY store_id, DATE(order_ts)
) s
ON t.store_id = s.store_id AND t.order_date = s.order_date
WHEN MATCHED THEN UPDATE SET
  revenue = t.revenue + s.revenue,
  orders  = t.orders + s.orders
WHEN NOT MATCHED THEN INSERT (store_id, order_date, revenue, orders)
  VALUES (s.store_id, s.order_date, s.revenue, s.orders);

This MERGE is simplified and assumes raw_orders only receives inserts. If the client has updates or deletes, you must write extra logic for each type of change. That is precisely the work a dynamic table does for you.

The second trap: a newly created task is always suspended. It will not start running on schedule until you run the statement below.

ALTER TASK merge_daily_revenue RESUME;

How to check: insert more data, wait one cycle, then compare daily_revenue_manual with daily_revenue from Step 1. The two tables should show the same figures. Then SELECT from the stream again: this time the result should be empty, because the MERGE moved the offset forward.

The third trap only shows up in production

A stream goes stale when its offset falls outside the data retention period of the source table. Suppose a task stays suspended over a long holiday and nobody notices. By the time anyone looks, the offset may have moved past the retention window and the stream is stale.

So if you choose streams and tasks for a client, put task state and stream staleness into the alerting from day one. Do not wait until the client’s dashboard freezes.

Which approach should you recommend?

Snowflake’s decision guide is fairly clear. For new SQL pipelines spanning several tables, prefer dynamic tables. Choose streams and tasks when the pipeline needs stored procedures, MERGE or external function calls.

Snowflake’s 2022 blog post introducing Dynamic Tables adds one more criterion: choose streams and tasks when you need full control over incremental processing. An analysis on Data Engineer Academy sums up the trade-off: you give up some low-level control and in return build far less “plumbing.”

Discovery question If the client says “yes”
Is the logic only SELECT, JOIN, GROUP BY? Dynamic table
Does any step need to call an API or external function? Streams and Tasks
Is the operations team small and reluctant to maintain many objects? Dynamic table
Do you need to decide exactly when and how to MERGE? Streams and Tasks

Open the first conversation with the client with two questions: how fast does the data change, and how stale can the numbers be? The answer to the second is almost exactly the TARGET_LAG value you will set.

Turn the exercise into evidence on your CV

Do not stop at saying you “know Snowflake.” Show that you have weighed the options: put both versions in a repo with a short README covering the three traps and why you would choose each approach.

On a CV, a line such as “moved a pipeline from full recompute to incremental, with criteria for choosing between dynamic tables and streams with tasks” says more than a list of tools.

When reading job descriptions, look for phrases like “incremental,” “CDC” or “data freshness.” They signal that the job will put you in front of the very choice you have just practiced.

The next time a client asks for a “real-time dashboard,” you have a more honest answer: real-time is usually just a TARGET_LAG number both sides agree on.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
7 sources
Read next on the roadmap · Stage 2: Broad engineeringAccessDenied in a customer's AWS usually hides in six placesBoth the customer's trust policy and your own IAM policy must open the door, and ExternalId stops a confused deputy rather than acting as a password.