πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
NEWSLIVESearch All Content
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Topic: Multi-Region & Data Replication

Snowflake AdvancedMulti-Region⭐ Premium

Snowflake Advanced Β· Interview Prep

Multi-Region & Data Replication

Difficulty: Hard Β· Commonly asked at Netflix, Apple, Google

Interview Question

"Design a global data platform that serves users in US, Europe, and Asia with sub-100ms query latency. How do you handle data replication, failover, and data sovereignty requirements?"

ℹ️

Companies Asking This: Netflix (Staff Data Engineer), Apple (Principal Data Engineer), Google (Senior Cloud Architect), Amazon (L6 Data Engineer)


Multi-Region Architecture

Organization Level (Global Account)US-EAST-1(Primary)Production DB(Primary)Read ReplicasEU-WEST-1(Replica)Production DB(Replica)Read ReplicasAP-SOUTH-1(Replica)Production DB(Replica)Read ReplicasGlobal Replication (Cross-Region)

Database Replication

-- 1. Create primary database
CREATE DATABASE global_analytics
    DATA_RETENTION_TIME_IN_DAYS = 30;

-- 2. Enable replication to other regions
ALTER DATABASE global_analytics
    SET ENABLE_DATABASE_REPLICATION = TRUE;

-- 3. Create replica in another region
-- (From the secondary account in different region)
CREATE DATABASE global_analytics_failover
    AS REPLICA OF my_organization.my_account.global_analytics;

-- 4. Check replication status
SELECT 
    database_name,
    created_on,
    replication_status,
    primary_region,
    failover_region,
    last_refreshed_on
FROM snowflake.account_usage.replication_database_status
WHERE database_name = 'GLOBAL_ANALYTICS';

-- 5. Monitor replication lag
SELECT 
    database_name,
   DATEDIFF('minute', last_refreshed_on, CURRENT_TIMESTAMP()) AS replication_lag_minutes,
    CASE 
        WHEN DATEDIFF('minute', last_refreshed_on, CURRENT_TIMESTAMP()) > 60 THEN 'CRITICAL'
        WHEN DATEDIFF('minute', last_refreshed_on, CURRENT_TIMESTAMP()) > 15 THEN 'WARNING'
        ELSE 'HEALTHY'
    END AS lag_status
FROM snowflake.account_usage.replication_database_status;

-- 6. Refresh replica (manual if needed)
ALTER DATABASE global_analytics_failover REFRESH;

Failover & Failback

-- 1. Initiate failover to secondary region
-- (Run from secondary account)
ALTER DATABASE global_analytics_failover FAILOVER;

-- 2. Check failover status
SELECT 
    database_name,
    replication_status,
    failover_on,
    failover_region
FROM snowflake.account_usage.replication_database_status
WHERE database_name = 'GLOBAL_ANALYTICS_FAILOVER';

-- 3. After primary region recovers, failback
-- (Run from original primary account after it's restored)
ALTER DATABASE global_analytics_failover REFRESH;

-- 4. Initiate failback
-- (Run from original primary account)
ALTER DATABASE global_analytics FAILOVER;

Real-World Scenario: Netflix

Question: "How do you handle data sovereignty requirements where EU user data must stay in EU regions?"

Solution: Data Residency Pattern

-- 1. Create region-specific databases
CREATE DATABASE analytics_us
    COMMENT = 'US region analytics';

CREATE DATABASE analytics_eu
    COMMENT = 'EU region analytics - GDPR compliant';

CREATE DATABASE analytics_ap
    COMMENT = 'APAC region analytics';

-- 2. Create regional schemas with data residency
CREATE SCHEMA analytics_eu.gdpr_compliant
    COMMENT = 'GDPR compliant data - EU only';

-- 3. Use row-level security for data residency
CREATE TABLE analytics_eu.users (
    user_id VARCHAR(100),
    user_name VARCHAR(200),
    email VARCHAR(200),
    region VARCHAR(10),
    data_residency VARCHAR(10) DEFAULT 'EU'
);

-- 4. Create row access policy for data residency
CREATE OR REPLACE ROW ACCESS POLICY data_residency_policy 
AS (region VARCHAR) RETURNS BOOLEAN ->
    CASE
        WHEN CURRENT_ROLE() IN ('GLOBAL_ADMIN', 'DATA_STEWARD') THEN TRUE
        WHEN CURRENT_REGION() = 'EU-WEST-1' AND region = 'EU' THEN TRUE
        WHEN CURRENT_REGION() = 'US-EAST-1' AND region = 'US' THEN TRUE
        WHEN CURRENT_REGION() = 'AP-SOUTH-1' AND region = 'AP' THEN TRUE
        ELSE FALSE
    END;

-- 5. Apply policy to tables
ALTER TABLE analytics_eu.users ADD ROW ACCESS POLICY data_residency_policy ON (region);

-- 6. Create cross-region view for global analytics
CREATE OR REPLACE VIEW global_analytics.unified_users AS
SELECT 'US' AS data_region, * FROM analytics_us.users WHERE region = 'US'
UNION ALL
SELECT 'EU' AS data_region, * FROM analytics_eu.users WHERE region = 'EU'
UNION ALL
SELECT 'AP' AS data_region, * FROM analytics_ap.users WHERE region = 'AP';

Real-World Scenario: Apple

Question: "How do you optimize query latency for users in different regions while maintaining a single source of truth?"

Solution: Read Replicas + Local Caching

-- 1. Create read replicas in each region
-- Primary in US
CREATE WAREHOUSE us_analytics_wh
    WAREHOUSE_SIZE = 'LARGE'
    MIN_CLUSTER_COUNT = 2
    MAX_CLUSTER_COUNT = 6;

-- Read replica in EU (configured via account settings)
CREATE WAREHOUSE eu_analytics_wh
    WAREHOUSE_SIZE = 'LARGE'
    MIN_CLUSTER_COUNT = 2
    MAX_CLUSTER_COUNT = 6;

-- Read replica in APAC
CREATE WAREHOUSE ap_analytics_wh
    WAREHOUSE_SIZE = 'LARGE'
    MIN_CLUSTER_COUNT = 2
    MAX_CLUSTER_COUNT = 6;

-- 2. Create regional views
CREATE OR REPLACE VIEW analytics_us.regional_dashboard AS
SELECT * FROM global_analytics.dashboard_metrics
WHERE region IN ('US', 'GLOBAL');

CREATE OR REPLACE VIEW analytics_eu.regional_dashboard AS
SELECT * FROM global_analytics.dashboard_metrics
WHERE region IN ('EU', 'GLOBAL');

-- 3. Use query tags for routing
ALTER SESSION SET QUERY_TAG = '{"region": "eu", "workload": "dashboard"}';

-- 4. Monitor latency by region
SELECT 
    CASE 
        WHEN warehouse_name LIKE 'US_%' THEN 'US'
        WHEN warehouse_name LIKE 'EU_%' THEN 'EU'
        WHEN warehouse_name LIKE 'AP_%' THEN 'APAC'
        ELSE 'UNKNOWN'
    END AS region,
    AVG(total_elapsed_time_ms) / 1000 AS avg_latency_seconds,
    PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY total_elapsed_time_ms) / 1000 AS p95_latency
FROM snowflake.account_usage.query_history
WHERE start_time >= DATEADD(day, -7, CURRENT_TIMESTAMP())
GROUP BY 1;

Replication Cost and Refresh Cadence

Database replication bills for storage in every region that holds a copy, and the refresh schedule determines how much of your query budget goes to re-reading the same bytes. A replica refreshed every five minutes moves the full changed set twelve times an hour; a replica refreshed hourly moves it once. Between refreshes the replica serves whatever arrived last, so the cadence is a freshness-versus-cost decision, not a performance one β€” nobody pays more compute for querying an up-to-date replica, they pay more for the refresh itself.

Set the schedule from the consumer's tolerance rather than from a default. A regulatory reporting replica that regulators inspect monthly can refresh daily and save almost the whole refresh bill. An operational dashboard that drives support decisions needs minutes, and in that case you are better served by streaming changes with a stream and task than by hammering the replication endpoint. Also account for the fact that refresh is not free of coordination: Snowflake acquires a brief lock on the primary during the refresh, so a cadence measured in seconds on a large database will start to interfere with production writes. Measure the refresh duration from replication_database_status before you commit to anything under fifteen minutes.

Choosing a Failover Topology

There are three practical topologies and they differ in cost, recovery time, and how much traffic engineering you own.

TopologyExtra copiesRecovery objectiveTraffic change required
Warm standby replicaOne per regionMinutes, manual failoverRepoint the client region setting
Hot standby with automatic failoverOne per regionSub-minuteDNS or driver reconfiguration only
Active-active across regionsOne writer per regionNo failover neededNone, but conflict handling is yours

Active-active sounds like the winner until you confront the write problem. Snowflake replicates at the database level and does not merge two regions that both accept writes, so active-active means partitioning the write workload by region and reconciling reads β€” a design that suits globally sharded user data and suits nothing that must be globally unique. For the interview, state the trade-off explicitly: the cheapest correct answer for most platforms is a warm replica per region with a rehearsed manual failover and a documented recovery time objective, upgraded to hot standby only for the databases that carry a real revenue number.

What Sub-100ms Actually Requires

Latency budgets are won at the region boundary, not in the query planner. Round-trip time between continents is physics: a fiber path from Virginia to Frankfurt lands around 80 to 90 milliseconds before your query executes at all. Any architecture that answers a European dashboard from a US primary therefore has no headroom left for compute, and no amount of clustering keys will recover it. Put the compute next to the reader.

The practical design is one of two shapes. Either each region gets its own replica with a local warehouse and the routing layer sends users to their nearest region, or you accept regional replication only for the subset of tables the region actually reads and keep the rest central. Both work; the second is cheaper and the first is simpler to explain. What does not work is a hybrid where queries randomly land in a distant region because the connection pool was not pinned β€” validate the region of every query session in your monitoring and alert when a session from a European client tag executes against the US warehouse.

Rehearsing Failover Without Causing One

A failover you have never executed is a hypothesis. Rehearse it on a schedule using a clone of the replica rather than the replica itself, so the exercise cannot touch production availability: fail the clone over, run the Tier 1 dashboards against it, and record how long each step took. The rehearsal surfaces the failures that documentation hides β€” a role that exists only in the primary account, a stage whose storage integration was never granted to the replica, a warehouse size that does not exist in the target region.

Keep a written runbook with the exact commands, the account each command runs from, and the person authorized to execute it. Failover is a moment when the wrong person in the right seat is worse than the right person in the wrong one, because two people issuing failover and failback commands from different accounts can leave the database in a state neither intended. Review the timings after every rehearsal against your stated recovery objective, and treat a miss as a project rather than as a note.


Best Practices

StrategyUse Case
Database replicationDisaster recovery, read scaling
Read replicasReduce latency for remote users
Data residencyGDPR, data sovereignty compliance
Failover planningBusiness continuity
Monitoring replication lagEnsure data freshness

⚠️

Key Considerations:

  1. Replication lag β€” Monitor and alert on lag > threshold
  2. Data sovereignty β€” Ensure data stays in required regions
  3. Failover testing β€” Regularly test failover procedures
  4. Cost implications β€” Replication increases storage costs
  5. Network latency β€” Cross-region queries have higher latency

Key Takeaways

  • Replication copies a database to another region on a refresh schedule you choose; failover is the separate, rehearsed act of promoting the replica β€” measure lag from replication_database_status, not hope.
  • Data sovereignty is enforced with region-local databases plus row access policies, so residency survives the query path instead of depending on where someone deployed a warehouse.
  • Sub-100ms cross-region latency is a placement problem, not a tuning problem β€” continental round trips eat the whole budget, so put the replica and the warehouse next to the reader.
  • Rehearse failover against a clone of the replica with a written runbook and named executor, and time every step against the stated recovery objective after each drill.
πŸ”’

Premium Content

Topic: Multi-Region & Data Replication

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-17

β€”
β˜†β˜†β˜†β˜†β˜†
0 ratings

Rate & Feedback

Advertisement