Multi-Region Architecture
In a multi-region deployment, your CockroachDB cluster spans multiple geographic regions, with nodes in each region:- Region: A geographic area (e.g.,
us-east,eu-west,asia-southeast) - Availability Zone: A fault-isolated location within a region
- Node Locality: Each node is tagged with its region and zone at startup
Node localities are set via startup flags like
--locality=region=us-east,zone=us-east-1. CockroachDB uses these locality tags to make intelligent placement decisions for data and leases.Why Multi-Region?
Deploying across regions provides:- Low-latency access: Users in each region read/write from nearby nodes
- Region-level resilience: Survive entire region outages
- Regulatory compliance: Keep data in specific geographic boundaries
- Disaster recovery: Data is automatically distributed across failure domains
Survival Goals
CockroachDB lets you choose how much failure your database can tolerate:Zone Survival (Default)
Zone Survival (Default)
Survives: Single availability zone failure within a regionConfiguration:
- 3 replicas spread across 3 availability zones in a region
- Requires a majority (2 of 3) to remain available
- Low-latency writes (within one region)
- Low-latency local reads
- Higher-latency remote reads (unless using follower reads)
Region Survival
Region Survival
Survives: Entire region failureConfiguration:
- At least 5 replicas spread across 3+ regions
- Requires a majority to remain available across regions
- Higher-latency writes (cross-region consensus required)
- Low-latency local reads with proper table locality
- Increased resilience comes with latency tradeoff
Survival Formula
The number of simultaneous failures you can tolerate:| Regions | Zone Survival | Region Survival |
|---|---|---|
| 1 region (3 zones) | 1 zone | N/A |
| 3 regions | 1 zone per region | 1 region |
| 5 regions | 1 zone per region | 2 regions |
Table Localities
Different tables have different access patterns. CockroachDB provides three table locality options to optimize for your workload:Regional by Table (Default)
Best for: Tables accessed primarily from one region Behavior:- All replicas for the table are in a single “home” region
- Low-latency reads and writes from the home region
- Higher-latency access from other regions
Performance Characteristics
Performance Characteristics
- Writes from home region: Low latency (intra-region consensus)
- Writes from remote region: High latency (cross-region network)
- Reads from home region: Low latency (local leaseholder)
- Reads from remote region: High latency unless using follower reads
users table for a US-based application where most users are in us-east.Regional by Row
Best for: Tables where different rows are accessed from different regions Behavior:- Each row is assigned a “home region” (typically via a
crdb_regioncolumn) - Rows are automatically partitioned by region
- Each region’s rows have their leaseholder in that region
Performance Characteristics
Performance Characteristics
- Writes to row’s home region: Low latency (local consensus)
- Writes from remote region: Higher latency (cross-region routing)
- Reads from row’s home region: Low latency (local leaseholder)
- Reads from remote region: Low latency for stale reads via follower reads
orders table where each order is tied to a user’s region and should be fast to access from that region.Global Tables
Best for: Small, read-heavy tables accessed from all regions Behavior:- Data is replicated to all regions
- Non-voting replicas in remote regions serve low-latency reads
- Writes have higher latency (must achieve consensus)
Performance Characteristics
Performance Characteristics
- Writes from any region: Higher latency (cross-region consensus required)
- Reads from any region: Low latency (local non-voting replica)
product_catalog table that rarely changes but is read frequently from all regions.Configuration Decision Matrix
Choose your configuration based on your requirements:| Requirement | Survival Goal | Table Locality | Result |
|---|---|---|---|
| Single region, HA | Zone | Regional by Table | Low latency, tolerates zone failures |
| Multi-region app, HA | Zone | Regional by Row | Low latency per region, can’t survive region failure |
| Multi-region app, resilient | Region | Regional by Row | Higher write latency, survives region failure |
| Read-mostly global | Region | Global | Low-latency reads everywhere, higher write latency |
Assess Your Needs
Determine:
- Are users in one region or many?
- Can you tolerate region-level failures?
- What’s your read vs. write ratio?
Choose Survival Goal
- Need automatic region failover? → Region survival
- Zone-level HA sufficient? → Zone survival
Select Table Localities
- Single region primary? → Regional by Table
- Data belongs to users in different regions? → Regional by Row
- Read-heavy reference data? → Global
Setting Up Multi-Region
Add Regions to Database
Configure Survival Goal
Set Table Localities
When you set a database to REGIONAL BY ROW, CockroachDB automatically adds a
crdb_region column to track each row’s home region. You can also define your own partitioning column.Advanced Patterns
Secondary Regions
Define a secondary region for faster failover and read replicas:- Faster follower reads from the secondary region
- Quicker promotion to primary if the primary region fails
Follower Reads for Multi-Region
Reduce cross-region latency for reads that can tolerate slight staleness:Geo-Partitioned Leaseholders
For REGIONAL BY ROW tables, explicitly prefer leaseholders in each partition’s home region:- US-East rows are served by leaseholders in us-east
- US-West rows are served by leaseholders in us-west
- EU-West rows are served by leaseholders in eu-west
Performance Tuning
Clock Skew Considerations
Multi-region deployments are sensitive to clock skew:Optimizing Cross-Region Queries
Avoid Cross-Region Joins
Avoid Cross-Region Joins
Joins across tables in different regions require cross-region communication:Solutions:
- Denormalize data to reduce joins
- Co-locate related tables in the same region
- Use REGIONAL BY ROW with matching region columns
Batch Cross-Region Writes
Batch Cross-Region Writes
Multiple writes to the same region should be batched:This reduces cross-region round trips from N to 1.
Monitoring Multi-Region Health
Key metrics to monitor:- Cross-region latency: Track network latency between regions
- Replica distribution: Ensure replicas are balanced across regions
- Leaseholder distribution: Verify leaseholders are in preferred regions
- Follower read usage: Measure % of reads served by followers
Common Pitfalls
See Also
- Distributed Transactions - How transactions work across regions
- Data Replication - Understanding replication mechanics
- Resilience and Recovery - Multi-region backup strategies