Disaster Recovery: Replication, Failover & DR Guide
Learn Snowflake business continuity with replication, failover, and disaster recovery.
20+ years shipping high-throughput database systems. Everything here is grounded in real deployments.
- ✓Basic understanding of Snowflake architecture (warehouses, databases, accounts).
- ✓Access to at least two Snowflake accounts (primary and secondary) on Business Critical Edition or higher.
- ✓Familiarity with SQL commands for account and database administration.
- ✓Knowledge of your organization's RPO and RTO requirements.
- Snowflake provides replication at the database level across regions/clouds.
- Failover can be manual or automatic using client redirect.
- Disaster recovery requires careful planning of RPO and RTO.
- Use Snowflake's replication features to minimize downtime.
- Test failover regularly to ensure readiness.
Think of Snowflake as a library with multiple branches. If one branch burns down, you can still borrow books from another branch because copies exist. Replication is like making photocopies of all books and sending them to other branches. Failover is like automatically redirecting patrons to the nearest open branch. Disaster recovery is the plan to get the damaged branch rebuilt and restocked.
Imagine your company's entire data warehouse—customer orders, financial records, real-time analytics—is hosted on Snowflake. One day, a regional cloud provider outage takes down your primary Snowflake account. Without a disaster recovery plan, your business grinds to a halt. This is where Snowflake's business continuity features come in.
Snowflake offers robust replication and failover capabilities to ensure your data remains available even during catastrophic failures. Whether you need cross-region replication for geographic redundancy or cross-cloud replication to avoid vendor lock-in, Snowflake provides the tools to design a resilient architecture.
In this tutorial, you'll learn how to set up database replication, perform failover and failback, and implement a comprehensive disaster recovery strategy. We'll cover real-world production incidents, debugging guides, and best practices to keep your data safe and accessible. By the end, you'll be able to configure Snowflake for high availability and confidently handle outages.
Understanding Snowflake's Business Continuity Model
Snowflake's architecture separates storage and compute, allowing for unique disaster recovery capabilities. Business continuity in Snowflake revolves around three key concepts: replication, failover, and failback.
Replication is the process of copying databases from a primary account to one or more secondary accounts. These secondary accounts can be in different regions or even different cloud providers. Replication is asynchronous, meaning there is some lag between when data is written to the primary and when it appears on the secondary. This lag determines your Recovery Point Objective (RPO).
Failover is the act of switching from the primary account to a secondary account during a disaster. Snowflake supports manual failover (where you explicitly promote a secondary to primary) and automatic failover via client redirect (where the Snowflake service automatically redirects connections to a healthy account).
Failback is the process of returning to the original primary after the disaster is resolved. This involves reversing the replication direction and ensuring data consistency.
Snowflake also offers a feature called 'Business Critical Edition' which includes enhanced replication and failover options. The following sections will guide you through setting up these features.
Setting Up Database Replication
To set up replication, you need at least two Snowflake accounts: a primary and a secondary. Both accounts must be on the same edition (e.g., Business Critical) and have the same cloud platform (or different if cross-cloud).
Step 1: Enable replication on the primary account. Step 2: Create a replication link between accounts. Step 3: Enable replication for specific databases.
Here's how to do it using SQL commands. First, on the primary account, run:
ALTER ACCOUNT SET ENABLE_REPLICATION = TRUE;
Then, on the primary, create a replication link to the secondary account:
CREATE REPLICATION LINK my_link AS REPLICATION OF ACCOUNT TO ACCOUNT <secondary_account_locator>;
Now, enable replication for a database:
ALTER DATABASE sales_db ENABLE REPLICATION TO ACCOUNTS <secondary_account_locator>;
On the secondary account, you must create the database as a replica:
CREATE DATABASE sales_db AS REPLICA OF <primary_account_locator>.sales_db;
Once created, replication starts automatically. You can monitor progress using SHOW REPLICATION DATABASES.
Performing Manual Failover and Failback
When a disaster strikes, you need to promote a secondary account to primary. This is a manual process unless you've configured automatic failover.
Manual Failover Steps: 1. Verify that the secondary account is healthy and has the latest data. 2. On the secondary account, promote it to primary:
ALTER ACCOUNT SET PRIMARY = TRUE;
This command makes the secondary account the new primary. All databases that were replicas become primary databases.
- Update your application connection strings to point to the new primary account URL.
Failback Steps: After the original primary is restored, you need to reverse replication and fail back.
- On the new primary (original secondary), enable replication back to the original primary:
ALTER DATABASE sales_db ENABLE REPLICATION TO ACCOUNTS <original_primary_locator>;
- On the original primary, create the database as a replica:
CREATE DATABASE sales_db AS REPLICA OF <new_primary_locator>.sales_db;
- Once replication is caught up, promote the original primary back:
ALTER ACCOUNT SET PRIMARY = TRUE;
- Update connection strings again.
Configuring Automatic Failover with Client Redirect
Snowflake offers automatic failover through client redirect. When enabled, the Snowflake service monitors the health of your primary account. If it detects an outage, it automatically redirects new connections to a secondary account.
To enable automatic failover: 1. Ensure replication is set up as described earlier. 2. On the primary account, configure failover objects:
ALTER ACCOUNT SET FAILOVER_OBJECT = '<secondary_account_locator>';
- On the secondary account, set it to accept failover:
ALTER ACCOUNT SET ACCEPT_FAILOVER = TRUE;
- Optionally, set a failover group to include multiple databases:
CREATE FAILOVER GROUP my_group OBJECT_TYPES = DATABASES ALLOWED_DATABASES = (sales_db, analytics_db);
Now, when the primary account becomes unavailable, Snowflake will automatically redirect new connections to the secondary. Existing connections may be dropped and need to reconnect.
You can test automatic failover by simulating an outage (e.g., disabling the primary account temporarily).
Monitoring Replication and Failover Health
Continuous monitoring is essential to ensure your disaster recovery plan works. Snowflake provides several views and functions to track replication and failover status.
- SHOW REPLICATION DATABASES: Shows replication status and lag.
- SNOWFLAKE.ACCOUNT_USAGE.REPLICATION_USAGE_HISTORY: Historical replication lag data.
- SNOWFLAKE.ACCOUNT_USAGE.FAILOVER_EVENTS: Logs of failover events.
- SYSTEM$LAST_REPLICATION_TIMESTAMP: Returns the timestamp of the last replicated transaction for a database.
Set up alerts for replication lag exceeding your RPO. For example, use Snowflake's task and notification integration to send an email when lag > 5 minutes.
Example alert setup:
CREATE OR REPLACE TASK check_replication_lag WAREHOUSE = my_wh SCHEDULE = '5 MINUTE' AS CALL SYSTEM$SEND_EMAIL( 'my_int', 'admin@example.com', 'Replication Lag Alert', 'Lag is high: ' || (SELECT MAX(REPLICATION_LAG_SECONDS) FROM SNOWFLAKE.ACCOUNT_USAGE.REPLICATION_USAGE_HISTORY) );
Cross-Cloud Replication and Multi-Region Strategies
Snowflake supports replication across different cloud providers (AWS, Azure, GCP) and regions. This is crucial for avoiding vendor lock-in and meeting compliance requirements.
Cross-cloud replication works similarly to cross-region replication, but requires that both accounts are on Business Critical Edition (or higher). The setup steps are identical, but you must ensure network connectivity between clouds (Snowflake handles this).
Multi-region strategies: For maximum resilience, replicate to at least two secondary accounts in different geographic regions. For example, primary on AWS us-east-1, secondary on AWS eu-west-1, and another secondary on Azure eastus.
- Cross-cloud replication may have higher latency and cost.
- Data sovereignty laws may require data to stay within certain regions.
- Failover across clouds may require additional configuration for external objects (e.g., stages, integrations).
Example: Replicate to a different cloud:
-- On primary (AWS) ALTER DATABASE sales_db ENABLE REPLICATION TO ACCOUNTS 'AZ12345'; -- Azure account
-- On secondary (Azure) CREATE DATABASE sales_db AS REPLICA OF 'AWS12345'.sales_db;
Best Practices for Disaster Recovery Testing
A disaster recovery plan is only as good as its last test. Regular testing ensures that your team knows the procedures and that the configuration works.
Best practices: 1. Schedule quarterly failover drills in a non-production environment. 2. Automate testing using Snowflake's SQL API or Terraform. 3. Validate data consistency after failover by comparing row counts or checksums. 4. Document the runbook with exact commands and contact information. 5. Include application teams in testing to ensure connection strings and authentication work.
Example test script:
-- Simulate failover ALTER ACCOUNT SET PRIMARY = TRUE; -- Run queries on new primary SELECT COUNT(*) FROM sales_db.orders; -- Failback ALTER ACCOUNT SET PRIMARY = FALSE; -- Not a real command; use proper failback steps
Use a separate test account to avoid impacting production.
The Cross-Region Outage That Almost Froze a Fintech
- Always configure cross-region replication for critical data.
- Test failover procedures regularly, not just during incidents.
- Understand that Snowflake does not automatically failover; you must set it up.
- Monitor replication lag to ensure RPO targets are met.
- Document and practice the failover runbook.
ALTER ACCOUNT SET FAILOVER_MODE = 'MANUAL';ALTER ACCOUNT <secondary> SET PRIMARY;| File | Command / Code | Purpose |
|---|---|---|
| check_replication.sql | SHOW REPLICATION DATABASES; | Understanding Snowflake's Business Continuity Model |
| setup_replication.sql | ALTER ACCOUNT SET ENABLE_REPLICATION = TRUE; | Setting Up Database Replication |
| failover.sql | ALTER ACCOUNT SET PRIMARY = TRUE; | Performing Manual Failover and Failback |
| auto_failover.sql | ALTER ACCOUNT SET FAILOVER_OBJECT = 'XY12345'; | Configuring Automatic Failover with Client Redirect |
| monitor_replication.sql | SELECT DATABASE_NAME, REPLICATION_LAG_SECONDS | Monitoring Replication and Failover Health |
| cross_cloud_replication.sql | ALTER DATABASE sales_db ENABLE REPLICATION | Cross-Cloud Replication and Multi-Region Strategies |
| test_failover.sql | ALTER ACCOUNT SET PRIMARY = TRUE; | Best Practices for Disaster Recovery Testing |
Key takeaways
Common mistakes to avoid
4 patternsNot enabling replication for all critical databases.
Assuming automatic failover works without configuration.
Failing to update connection strings after failover.
Not testing failover regularly.
Interview Questions on This Topic
Explain how Snowflake replication works and what determines RPO.
Frequently Asked Questions
20+ years shipping high-throughput database systems. Everything here is grounded in real deployments.
That's Snowflake. Mark it forged?
4 min read · try the examples if you haven't