By Rohit Ray · Independent educational lesson · Explore this visual lab

Module 13 · Lesson 6 of 11Detailed study · about 22 min

Watermarks, CDC and idempotent delivery

A watermark records how far ingestion has safely processed a source. It must advance with committed output, not when a batch merely starts.

Understand the idea

A WHERE updated_at > last_time query can miss rows sharing the last timestamp or corrections with older timestamps. A composite timestamp/ID cursor or overlap window helps only if its source contract is understood. Overlap still requires deduplication and cannot discover arbitrary hard deletes.

Key ideas in simple English
ConceptWhat it means
WatermarkLast safely accepted delivery position.
CDCCaptures change operations including deletions where supported.
ReplayThe same business input arrives again.
IdempotenceReprocessing does not duplicate or regress business state.

A concrete example

A WHERE updated_at > last_time query can miss rows sharing the last timestamp or corrections with older timestamps. A composite timestamp/ID cursor or overlap window helps only if its source contract is understood. Overlap still requires deduplication and cannot discover arbitrary hard deletes.

Remember: A reliable cursor needs an ordered committed-source contract; allocation order alone is insufficient.

Explain it step by step · full theory

Understand the concept

A WHERE updated_at > last_time query can miss rows sharing the last timestamp or corrections with older timestamps. A composite timestamp/ID cursor or overlap window helps only if its source contract is understood. Overlap still requires deduplication and cannot discover arbitrary hard deletes.

Our lab uses immutable, committed delivery batches with increasing DELIVERY_ID. This is a teaching contract: IDs allocated before concurrent transactions commit are not automatically safe watermarks. Real extraction must guarantee no lower IDs can appear after a batch closes.

Apply it in practice

EVENT_ID identifies a business change independently of delivery. The same event can be delivered at a new position and must be ignored if its payload agrees. Reusing an event ID with conflicting content is an error, not a tie to resolve arbitrarily.

Choose streams/tasks when you need explicit CDC consumption and transactions. Choose a dynamic table when maintaining a query result fits. Neither removes the need to define business identity and how old corrections should affect history.

Words used in this lesson
Watermark
Last safely accepted delivery position.
CDC
Captures change operations including deletions where supported.
Replay
The same business input arrives again.
Idempotence
Reprocessing does not duplicate or regress business state.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 2

Watermarks, CDC and idempotent delivery

Watermark
CDC
Idempotence

Understand the flow

A watermark records how far ingestion has safely processed a source. It must advance with committed output, not when a batch merely starts.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Understand the flow

    A watermark records how far ingestion has safely processed a source. It must advance with committed output, not when a batch merely starts.

  2. Apply the contract

    A reliable cursor needs an ordered committed-source contract; allocation order alone is insufficient.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Manual learning exercise. Production deployment needs source-specific contracts, access controls, orchestration and operational monitoring.

Watermarks, CDC and idempotent delivery — SQL example

Definition: A watermark records how far ingestion has safely processed a source. It must advance with committed output, not when a batch merely starts.

When to use: Follow the isolated customer-history lab in lesson order.

Example: 3 deliveries but 2 business events. An output row per delivery would duplicate E1.

SQL · example
WITH delivered(DELIVERY_ID,EVENT_ID) AS (SELECT * FROM VALUES (1,'E1'),(2,'E2'),(3,'E1')) SELECT COUNT(*) AS DELIVERIES,COUNT(DISTINCT EVENT_ID) AS BUSINESS_EVENTS FROM delivered;

What to expect and why

3 deliveries but 2 business events. An output row per delivery would duplicate E1.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Does a larger allocated ID always prove all lower IDs have committed?

Try it yourself

Explain with the example: Does a larger allocated ID always prove all lower IDs have committed?

Compare your reasoning

A reliable cursor needs an ordered committed-source contract; allocation order alone is insufficient.

Official sources and curriculum

Module 13 · See module scope