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

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

Prove rollback, retry and data-quality invariants

A reliable pipeline has observable failure behavior and checks that detect duplicate current rows, overlapping history and broken relationships.

Understand the idea

Append C2’s April move to Jaipur and intentionally fail before commit. The dimension must remain Delhi, the cursor must stay at 6 and the success audit must still contain two rows. Only the failure log should grow. Run the failing CALL separately because your SQL client may stop on the error.

Key ideas in simple English
ConceptWhat it means
RollbackUndo business changes and watermark advancement.
RetryReapply the same pending window safely.
AuditSeparate successful commits from failure evidence.
Quality invariantA rule that must remain true after every accepted batch.

A concrete example

Append C2’s April move to Jaipur and intentionally fail before commit. The dimension must remain Delhi, the cursor must stay at 6 and the success audit must still contain two rows. Only the failure log should grow. Run the failing CALL separately because your SQL client may stop on the error.

Remember: Record failures separately while keeping the business transaction and cursor unchanged until a successful retry.

Explain it step by step · full theory

Understand the concept

Append C2’s April move to Jaipur and intentionally fail before commit. The dimension must remain Delhi, the cursor must stay at 6 and the success audit must still contain two rows. Only the failure log should grow. Run the failing CALL separately because your SQL client may stop on the error.

Retry without the failure switch. Now C2 has Delhi until April and Jaipur from April onward. The watermark reaches 7 and a third success audit records one delivery. A skipped sequence value after rollback is normal and not a missing customer.

Apply it in practice

A schema change or incompatible attribute should stop or quarantine according to a declared policy. Never silently cast a bad value to NULL and publish it as if it were valid. Keep raw evidence, error category, batch identifier and a reviewed reprocessing procedure.

For Dev, QA and Prod, use separate approved databases, roles, credentials and orchestrators. Promote code and controlled configuration; do not copy customer secrets into development. Run one writer per environment and prevent a QA task from targeting the production watermark.

Words used in this lesson
Rollback
Undo business changes and watermark advancement.
Retry
Reapply the same pending window safely.
Audit
Separate successful commits from failure evidence.
Quality invariant
A rule that must remain true after every accepted batch.

See how it works

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

Open the interactive explanation
Interactive explainer1 / 2

Prove rollback, retry and data-quality invariants

Rollback
Retry
Quality invariant

Understand the flow

A reliable pipeline has observable failure behavior and checks that detect duplicate current rows, overlapping history and broken relationships.

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 reliable pipeline has observable failure behavior and checks that detect duplicate current rows, overlapping history and broken relationships.

  2. Apply the contract

    Record failures separately while keeping the business transaction and cursor unchanged until a successful retry.

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.

Prove rollback, retry and data-quality invariants — SQL example

Definition: A reliable pipeline has observable failure behavior and checks that detect duplicate current rows, overlapping history and broken relationships.

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

Example: Before retry: watermark 6 and C2 Delhi remains current. After retry: watermark 7, five dimension versions, audit (4,4),(6,2),(7,1). The three invariant queries return zero rows.

SQL · example
INSERT INTO INPUT_EVENTS VALUES (7,'E5','C2','Jaipur','2026-04-01');
CALL APPLY_CUSTOMER_BATCH(TRUE);
-- Expected error: run the following checks separately afterward.
SELECT * FROM PIPELINE_STATE;
SELECT * FROM REJECT_LOG ORDER BY FAILED_AT DESC;
-- Retry only after observing the rollback:
CALL APPLY_CUSTOMER_BATCH(FALSE);
SELECT CUSTOMER_ID,COUNT_IF(IS_CURRENT) AS CURRENT_ROWS
 FROM DIM_CUSTOMER GROUP BY CUSTOMER_ID HAVING COUNT_IF(IS_CURRENT)<>1;
SELECT CUSTOMER_SK,COUNT(*) FROM DIM_CUSTOMER GROUP BY CUSTOMER_SK HAVING COUNT(*)>1;
SELECT * FROM DIM_CUSTOMER WHERE VALID_TO<=VALID_FROM;
SELECT BATCH_END,DELIVERIES FROM RUN_AUDIT ORDER BY BATCH_END;

What to expect and why

Before retry: watermark 6 and C2 Delhi remains current. After retry: watermark 7, five dimension versions, audit (4,4),(6,2),(7,1). The three invariant queries return zero rows.

Check your understanding

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

Does a failed batch belong in the successful-commit audit?

Try it yourself

Explain with the example: Does a failed batch belong in the successful-commit audit?

Compare your reasoning

Record failures separately while keeping the business transaction and cursor unchanged until a successful retry.

Official sources and curriculum

Module 13 · See module scope