4: Storage and Data Protection

    Implement Time Travel, Fail-safe, and cross-region and cross-cloud replication.

    Time Travel and Fail-safe form the two-stage data recovery surface that distinguishes Snowflake from systems that depend on external backup tooling. Once a Permanent table is created on Enterprise Edition or higher, every DML, DDL, drop, or replace operation produces a historical version that the engine retains for the configured Time Travel window followed by a fixed Fail-safe window.

    Replication adds a third stage of protection by maintaining a synchronized copy of databases, roles, warehouses, and shares in a separate region or cloud, allowing a coordinated failover when an entire region becomes unavailable.

    The exam expects a data engineer to distinguish the retention windows for each table type, to write recovery queries against historical versions, to compute storage cost implications, and to design a replication topology that satisfies recovery time and recovery point objectives without violating governance constraints. This section walks through each of those areas in sequence:

    • beginning with the retention configuration surface,
    • moving through the recovery DML,
    • finishing with the replication topology used for regional and cross-cloud disaster recovery.

    Time Travel retention windows and edition dependencies

    How it works

    Snowflake stores historical versions of every table at the micro-partition level.

    When a row is updated, the underlying micro-partition is rewritten and the previous version is retained as part of the table history until the retention window expires.

    The window length is governed by the DATA_RETENTION_TIME_IN_DAYS parameter, which exists at account, database, schema, and table levels. The most specific value wins.

    A table that inherits 7 days from its schema but is explicitly altered to 30 days retains for 30 days, and a schema that inherits 30 days from its database but is set to 1 day applies the 1 day value to every table it owns that does not carry an explicit override. The valid range depends on the edition and the table type.

    • Standard Edition accounts cap retention at 1 day for every object.
    • Enterprise Edition and higher accounts cap retention at 90 days for Permanent tables and at 1 day for Transient and Temporary tables.

    Setting DATA_RETENTION_TIME_IN_DAYS to 0 disables Time Travel for that object, which is the only supported way to recover the storage immediately on UPDATE or DELETE.

    Disabling Time Travel also disables UNDROP for that object, so the parameter cannot be set to zero on tables that require dropped-object recovery.

    📊 Limit: Permanent tables on Enterprise Edition and higher allow a Time Travel range of 0 to 90 days. Transient and Temporary tables allow a Time Travel range of 0 or 1 day only, regardless of edition. The default on every new object is 1 day, inherited through the account chain if no closer override exists.

    The MAX_DATA_EXTENSION_TIME_IN_DAYS parameter is a separate control that bounds how long Snowflake will extend retention when a Stream consumer is lagging.

    When a Stream points at a table, the engine prevents micro-partition expiration until the Stream is consumed or the extension cap is reached. The default is 14 days and the maximum is 90 days.

    A Stream that is never consumed will pin storage cost until the extension cap is hit, after which the Stream becomes stale and the historical partitions can be reclaimed by the engine.

    The MAX_DATA_EXTENSION_TIME_IN_DAYS parameter exists at account, database, schema, and table levels, with the same most-specific-wins inheritance as the retention parameter.

    Setting the extension cap to a value smaller than the DATA_RETENTION_TIME_IN_DAYS is valid and is the right control on tables that should never have Time Travel extended past a known business window even if Streams lag.

    💡 Exam Trap: DATA_RETENTION_TIME_IN_DAYS and MAX_DATA_EXTENSION_TIME_IN_DAYS are independent. A table with 1-day Time Travel and a 14-day extension cap will still pin two weeks of partitions if a Stream has been stale for the full extension window. The exam tests this distinction in stream-cost questions where the candidate must compute storage cost from both parameters.

    Configuring retention at the right scope

    The placement of the DATA_RETENTION_TIME_IN_DAYS setting drives a recurring set of exam scenarios.

    • Account-level changes apply to every newly created object that does not override the value, but do not retroactively shorten retention on existing tables.
    • Database-level changes propagate to schemas created after the change.
    • Schema-level changes propagate to tables created after the change.
    • Table-level changes apply immediately to subsequent micro-partition versions.
    -- Account-level baseline
    ALTER ACCOUNT SET DATA_RETENTION_TIME_IN_DAYS = 7;
    
    -- Database override for a sensitive analytics surface
    ALTER DATABASE FIN_PROD SET DATA_RETENTION_TIME_IN_DAYS = 30;
    
    -- Schema override for an audit-grade subject area
    ALTER SCHEMA FIN_PROD.LEDGER SET DATA_RETENTION_TIME_IN_DAYS = 90;
    
    -- Table override for an ephemeral staging table
    ALTER TABLE FIN_PROD.LEDGER.STG_DAILY_BATCH 
     SET DATA_RETENTION_TIME_IN_DAYS = 0;
    

    Lowering retention on a Permanent table does not delete historical partitions retroactively. Versions that were created while the higher retention was in effect remain protected until their original window expires.

    Raising retention applies only to newly produced versions; partitions that were already purged from Time Travel cannot be recovered by re-enabling a larger window. This asymmetry is intentional: the engine cannot resurrect partitions whose storage has been released, but it can shorten the protection of partitions that have not yet been released.

    ⚠️ Anti-Pattern: Setting DATA_RETENTION_TIME_IN_DAYS to 90 on a high-churn staging table that receives multi-billion-row MERGE operations every refresh. Every refresh rewrites a large fraction of micro-partitions, and the historical versions accumulate storage cost that often exceeds the value of the active dataset within the first month. Staging tables that feed downstream consumers should be Transient, or Permanent with a 1-day retention if Fail-safe protection is acceptable but not required.

    Querying historical versions with AT and BEFORE

    The Time Travel surface is exposed through three clauses on FROM: AT (TIMESTAMP), AT (OFFSET), and BEFORE (STATEMENT). All three return the state of the table at the requested point in the retention window.

    AT (TIMESTAMP) accepts a TIMESTAMP_LTZ or TIMESTAMP_TZ literal. AT (OFFSET) accepts a negative number of seconds relative to current_timestamp.

    BEFORE (STATEMENT) accepts a query_id and returns the table state immediately before that statement committed.

    -- 30 seconds before now
    SELECT * FROM ORDERS AT (OFFSET => -30);
    
    -- Specific clock time inside the retention window
    SELECT * FROM ORDERS AT (TIMESTAMP => 
     '2099-04-12 14:00:00.000 -0700'::TIMESTAMP_TZ);
    
    -- The state immediately before a known bad statement
    SELECT * FROM ORDERS BEFORE (STATEMENT => 
     '01b1f1a4-0000-1234-0000-abcdefabcdef');
    

    The AT and BEFORE clauses can be combined with the CHANGES clause to extract the delta between two points in the retention window. CHANGES is a metadata read against the same micro-partition history that Streams use; it does not lock the table or block writers, and it does not require a Stream object to exist beforehand provided that change tracking metadata is present on the table.

    -- Net deltas in the last hour against a change-tracked source
    SELECT * 
    FROM ORDERS
    CHANGES(INFORMATION => DEFAULT)
    AT (OFFSET => -3600);
    

    A common exam pattern reads the table at two timestamps within the retention window and joins the results to construct a manual reconciliation report. The CHANGES clause replaces that pattern with a single read and a METADATA$ACTION column that classifies each row as INSERT or DELETE, with METADATA$ISUPDATE marking the two halves of an UPDATE.

    💡 Exam Trap: The CHANGES clause requires CHANGE_TRACKING = TRUE on the source table, or it requires a Stream object to have been created against the table at or before the start point. Without one of those, the query fails even if the data is still inside the Time Travel window. The fix is to issue ALTER TABLE ... SET CHANGE_TRACKING = TRUE proactively on tables that participate in delta validation workflows.

    UNDROP for tables, schemas, and databases

    DROP TABLE, DROP SCHEMA, and DROP DATABASE move the object into the metadata graveyard but do not delete the underlying micro-partitions.

    The object remains recoverable through UNDROP for the duration of its DATA_RETENTION_TIME_IN_DAYS window.

    UNDROP is purely a metadata operation, completes in milliseconds, and restores all dependent objects in a single statement when applied to a schema or database.

    DROP TABLE FIN_PROD.LEDGER.ORDERS;
    -- ... realize the mistake ...
    UNDROP TABLE FIN_PROD.LEDGER.ORDERS;
    

    If a new object has been created with the same fully qualified name after the drop, UNDROP fails.

    The recovery path in that scenario requires renaming the new object first, restoring the dropped object, and then deciding which version to retain.

    UNDROP also fails on objects whose DATA_RETENTION_TIME_IN_DAYS was set to 0 at the time of the drop, because the engine releases the metadata immediately when retention is disabled.

    🎯 Scenario: A pipeline operator drops a 12 TB ORDERS_HISTORY table by mistake and a downstream Task immediately recreates an empty table with the same name. The recovery path is to ALTER TABLE ORDERS_HISTORY RENAME TO ORDERS_HISTORY_EMPTY, then UNDROP TABLE ORDERS_HISTORY, then drop the empty placeholder. The original 12 TB table returns instantly because UNDROP is a metadata operation against the retained micro-partitions, with no data movement and no warehouse compute.

    Fail-safe semantics

    Key points

    Fail-safe is the 7-day grace period that follows the Time Travel window on Permanent objects.

    It is non-configurable, applies only to Permanent tables (Transient and Temporary tables have no Fail-safe), and is accessible only to Snowflake Support.

    The customer cannot query Fail-safe data through SQL; recovery requires opening a support case, and Snowflake reserves the right to take up to several hours to restore the data. Fail-safe is not a substitute for replication.

    It protects against accidental data loss during the 7-day window but does not protect against region-wide outages, and it is not retrievable on demand.

    Tables that require self-service rollback past the Time Travel window must be either replicated or backed up through scheduled clone-to-archive routines that capture point-in-time snapshots as independent Permanent objects.

    The exam frequently combines Time Travel and Fail-safe into a single retention question.

    A Permanent table with DATA_RETENTION_TIME_IN_DAYS = 30 is recoverable for 30 days through self-service and for a further 7 days through Fail-safe, giving a total of 37 days of protection.

    A Transient table with DATA_RETENTION_TIME_IN_DAYS = 1 is recoverable for 1 day only; there is no Fail-safe extension and no support-mediated recovery beyond the configured window.

    📊 Limit: Fail-safe window is 7 days, non-configurable, Permanent objects only. Restore is best-effort and may take up to several hours. The customer cannot read or copy Fail-safe data directly.

    Storage cost accounting for Time Travel and Fail-safe

    Time Travel and Fail-safe storage shows up in the TABLE_STORAGE_METRICS view inside ACCOUNT_USAGE. The columns ACTIVE_BYTES, TIME_TRAVEL_BYTES, FAILSAFE_BYTES, and RETAINED_FOR_CLONE_BYTES decompose the total storage footprint of every table. The last column captures bytes that remain pinned because a clone still references them; cloning is covered in detail in the third section of this chapter.

    SELECT 
     TABLE_CATALOG,
     TABLE_SCHEMA,
     TABLE_NAME,
     ACTIVE_BYTES / POW(1024, 4) AS active_tb,
     TIME_TRAVEL_BYTES / POW(1024, 4) AS tt_tb,
     FAILSAFE_BYTES / POW(1024, 4) AS fs_tb,
     RETAINED_FOR_CLONE_BYTES / POW(1024, 4) AS clone_tb
    FROM SNOWFLAKE.ACCOUNT_USAGE.TABLE_STORAGE_METRICS
    WHERE DELETED = FALSE
    ORDER BY tt_tb DESC
    LIMIT 50;
    

    Storage cost is billed monthly per terabyte-month.

    The breakdown above is the primary cost lever for storage optimization.

    A 5 TB Permanent fact table that receives a daily full rewrite with 90-day retention will hold roughly 90 days worth of historical partitions in Time Travel and 7 days in Fail-safe, multiplying the storage cost roughly 100-fold relative to the active footprint.

    Reducing retention to 7 days, or converting the table to Transient with no Fail-safe, drops the multiplier by an order of magnitude.

    Replication topology with replication and failover groups

    Replication moves objects from a source account to one or more target accounts on a configurable schedule.

    Failover adds the ability to promote a target account to primary in the event of a regional outage.

    Both are implemented through Replication Groups and Failover Groups, which package related objects into a single replicated unit so that databases, shares, roles, warehouses, and resource monitors fail over atomically rather than in independent partial states.

    Comparison

    • A Replication Group replicates objects but does not allow failover.
    • A Failover Group is a strict superset that adds promotion semantics.

    Failover Groups require Business Critical Edition or higher on both the source and target accounts.

    Replication Groups are available on Standard and above for databases, with object-type expansion at higher editions.

    -- Create a failover group covering two databases, all account roles, 
    -- warehouses, and resource monitors, replicated to two targets, 
    -- refreshed every 10 minutes
    CREATE FAILOVER GROUP fg_prod
     OBJECT_TYPES = DATABASES, ROLES, WAREHOUSES, RESOURCE MONITORS
     ALLOWED_DATABASES = FIN_PROD, OPS_PROD
     ALLOWED_ACCOUNTS = my_org.my_account_dr_east, my_org.my_account_dr_cloud2
     REPLICATION_SCHEDULE = '10 MINUTE';
    

    On the target account, the failover group is refreshed automatically at the configured cadence. An operator can also force a refresh with a manual command, or trigger promotion with PRIMARY:

    -- On the target account, force an immediate refresh
    ALTER FAILOVER GROUP fg_prod REFRESH;
    
    -- On the target account, promote to primary 
    -- (the former primary becomes a replica)
    ALTER FAILOVER GROUP fg_prod PRIMARY;
    

    The promote operation is the disaster recovery action.

    After PRIMARY, the new primary accepts writes and the former primary becomes read-only as a target of the same group.

    Failback is the same statement issued from the original account once the outage clears.

    Promotion is atomic across every object in the group, which means the application sees consistent role, warehouse, and database state on the new primary rather than a partial failover with mismatched permissions.

    💡 Exam Trap: Failover Groups require Business Critical Edition on both accounts. Promoting a failover group whose target account is on Standard Edition fails with a privilege error even if the source account is Business Critical. The exam often pairs an edition trap with a failover question, expecting the candidate to identify the missing edition upgrade as the resolution.

    Cross-region and cross-cloud replication

    Replication operates across regions and across cloud providers using Snowgrid, the inter-region transport that connects every Snowflake account. A failover group on AWS us-east-1 can target an account on Azure West Europe and another on GCP us-central1 in the same statement, producing a multi-cloud DR topology.

    The data path is encrypted, compressed, and consumes account-level replication credits charged through the REPLICATION_USAGE_HISTORY view.

    Object support varies by edition and by object type. The replication-eligible object catalog covers databases, shares, account-level roles, account-level grants, users, warehouses, resource monitors, network policies, integrations, external functions (definitions only), and several governance objects (tags, masking policies, row access policies).

    External tables, hybrid tables, and Apache Iceberg tables have specific replication paths; external table data is not replicated because it lives in the customer-managed bucket. Apache Iceberg tables are replicated through metadata and reference the same underlying object storage from the target account when the catalog integration permits cross-account access.

    -- Inspect replication cost across the last 30 days
    SELECT 
     START_TIME,
     DATABASE_NAME,
     CREDITS_USED,
     BYTES_TRANSFERRED / POW(1024, 4) AS tb_transferred
    FROM SNOWFLAKE.ACCOUNT_USAGE.REPLICATION_USAGE_HISTORY
    WHERE START_TIME >= DATEADD('day', -30, CURRENT_TIMESTAMP())
    ORDER BY START_TIME DESC;
    

    The REPLICATION_USAGE_HISTORY view is the right surface for chargeback because it attributes credit consumption to the source database, not the target. Cross-cloud replication carries a higher per-byte cost than same-cloud cross-region replication because of provider egress charges; the REPLICATION_GROUP_USAGE_HISTORY view exposes these on a per-group basis.

    Connection objects and client redirect

    Client redirect is the mechanism that allows applications to keep a single connection string after a failover. A connection object is created at the organization level with a primary account; when the failover group is promoted to a new primary, the connection object is repointed and clients reconnect to the new region without changing the URL.

    -- Create a redirectable connection on the secondary account
    CREATE CONNECTION app_conn 
     AS REPLICA OF my_org.my_account_east.app_conn;
    
    -- After promoting the failover group, swing the connection
    ALTER CONNECTION app_conn PRIMARY;
    

    Client redirect is available on Business Critical Edition or higher and requires a separate ORGADMIN-level configuration step to enable the organization for connection objects. The connection URL is stable across promotion events because the DNS layer is owned by Snowflake's organization service rather than by a per-account hostname.

    Decision Tree: Replication versus Failover Group selection

    ⚠️ Anti-Pattern: Configuring a separate per-database replication for ten databases that all belong to a single application. The right design is one Failover Group that wraps all ten databases, the warehouses, the roles, and the resource monitors. A single PRIMARY statement then promotes the entire application atomically. Per-database replication produces inconsistent failover states where some databases lag and roles point at the wrong primary.

    🎯 Scenario: A regulated workload runs on Business Critical in AWS us-east-1 and the auditor requires a 15-minute RPO with promotion to AWS us-west-2 inside 30 minutes. The design is a single Failover Group covering all production databases, account roles, warehouses, and resource monitors, with REPLICATION_SCHEDULE = '10 MINUTE' and a Connection object with client redirect. Quarterly drills issue ALTER FAILOVER GROUP fg_prod PRIMARY against us-west-2 and measure the elapsed time against the 30-minute SLO; the team verifies that the dashboard, write pipelines, and Snowpipe ingestion all resume on the new primary within the window.

    Decision Anchor

    When to use

    • Choose Time Travel when the recovery window is short (seconds to days) and the operator needs self-service rollback through SQL.
    • Choose Fail-safe when recovery requires going beyond the configured Time Travel window but is still inside the 7-day Fail-safe limit and a support case is acceptable.
    • Choose a Failover Group when the requirement is regional or cloud-level disaster recovery with promotion, atomic across databases, roles, warehouses, and shares.
    • Choose a Replication Group when the requirement is read-only cross-region distribution of databases without promotion, for example to feed regional analytics workloads from a central source of truth.

    Continue with the interactive course

    Track your progress, jump into practice questions and use the Shark AI tutor inside the Snowflake - SnowPro Advanced Data Engineer learning hub.