Globally distributed databases with multi-region replication
Managed: AWS Aurora Global → Self-hosted: TiDB (for learning, MySQL compatible)
Distributed SQL databases provide ACID transactions across multiple regions with automatic failover and data locality.
┌─────────────────────────────────────────────────────────────────┐
│ Distributed SQL Cluster │
│ │
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
│ │ Region 1 │◄────►│ Region 2 │◄────►│ Region 3 │ │
│ │ (nodes) │ │ (nodes) │ │ (nodes) │ │
│ └───────────┘ └───────────┘ └───────────┘ │
│ │ │ │ │
│ └──────────────────┴──────────────────┘ │
│ Replication │
└─────────────────────────────────────────────────────────────────┘
| Solution | Managed | Self-hosted | Compatibility | Protocol |
|---|---|---|---|---|
| Aurora Global | AWS | ✗ | MySQL/PostgreSQL | Proprietary |
| TiDB | TiDB Cloud | TiDB OSS | MySQL | Raft |
| CockroachDB | Cockroach Cloud | CockroachDB OSS | PostgreSQL | Raft |
| YugabyteDB | Yugabyte Cloud | YugabyteDB OSS | PostgreSQL | Raft |
| Cloud Spanner | GCP | ✗ | PostgreSQL-like | TrueTime |
┌─────────────────────────────────────────────────────────────────┐
│ Aurora Global Database │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Primary Region │ async │ Secondary Region│ │
│ │ (us-east-1) │ ──────────► │ (eu-west-1) │ │
│ │ │ <1s lag │ │ │
│ │ ┌───────────┐ │ │ ┌───────────┐ │ │
│ │ │ Writer │ │ │ │ Reader │ │ │
│ │ │ Instance │ │ │ │ Instances │ │ │
│ │ └───────────┘ │ │ └───────────┘ │ │
│ │ ┌───────────┐ │ │ ┌───────────┐ │ │
│ │ │ Reader │ │ │ │ Storage │ │ │
│ │ │ Instances │ │ │ │ (copy) │ │ │
│ │ └───────────┘ │ │ └───────────┘ │ │
│ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
- Replication lag: <1 second typical
- Failover: Promote secondary to primary (~1 minute)
- Read scaling: Read from any region
- Write: Single primary region only
Normal:
Primary (us-east-1) ──async──► Secondary (eu-west-1)
▲
Writes
Failover:
1. Detect primary failure
2. Promote secondary to primary (~1 min)
3. Update application endpoints
- MySQL compatible (familiar syntax)
- Horizontal scaling
- Strong consistency (Raft)
- Open source, active community
┌─────────────────────────────────────────────────────────────────┐
│ TiDB Cluster │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ TiDB │ │ TiDB │ │ TiDB │ SQL Layer │
│ │ Server │ │ Server │ │ Server │ (stateless) │
│ └────┬────┘ └────┬────┘ └────┬────┘ │
│ │ │ │ │
│ └────────────┼────────────┘ │
│ │ │
│ ┌─────────────────▼─────────────────┐ │
│ │ PD Cluster │ Placement Driver │
│ │ (scheduling, timestamp oracle) │ (metadata) │
│ └─────────────────┬─────────────────┘ │
│ │ │
│ ┌─────────┬───────┼───────┬─────────┐ │
│ │ │ │ │ │ │
│ ▼ ▼ ▼ ▼ ▼ │
│ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ Storage Layer │
│ │TiKV │ │TiKV │ │TiKV │ │TiKV │ │TiKV │ (Raft groups) │
│ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ │
└─────────────────────────────────────────────────────────────────┘
┌───────────────────┐ ┌───────────────────┐ ┌───────────────────┐
│ Region 1 │ │ Region 2 │ │ Region 3 │
│ (us-east-1) │ │ (us-west-2) │ │ (eu-west-1) │
│ │ │ │ │ │
│ TiDB + TiKV + PD │◄───►│ TiDB + TiKV + PD │◄───►│ TiDB + TiKV + PD │
│ │ │ │ │ │
└───────────────────┘ └───────────────────┘ └───────────────────┘
Raft Replication
-- Place data for EU users in EU region
CREATE PLACEMENT POLICY eu_policy
PRIMARY_REGION="eu-west-1"
REGIONS="eu-west-1,us-east-1,us-west-2";
-- Apply to table
ALTER TABLE eu_users PLACEMENT POLICY eu_policy;# Start TiDB cluster locally
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
tiup playground --tag multi-region \
--pd 3 \
--tikv 3 \
--tidb 2
# Connect with MySQL client
mysql -h 127.0.0.1 -P 4000 -u root Writes
│
▼
┌─────────────────┐ ┌─────────────────┐
│ Primary Region │ async │ Secondary Region│
│ (Writer) │ ──────────► │ (Reader) │
└─────────────────┘ └─────────────────┘
│
▼
Local Reads
- Aurora Global: Native support
- TiDB: Use follower-read or placement rules
- Trade-off: Simple, but writes have single point
┌─────────────────┐ ┌─────────────────┐
│ Region 1 │◄────────────►│ Region 2 │
│ (Read/Write) │ sync │ (Read/Write) │
└─────────────────┘ └─────────────────┘
- TiDB/CockroachDB: Supported with Raft
- Aurora: Not supported (single writer)
- Trade-off: Higher latency for consistency
EU Users ──► EU Region (EU data lives here)
US Users ──► US Region (US data lives here)
Asia Users ──► Asia Region (Asia data lives here)
- Data stays in user's region
- Low latency for local operations
- Compliance friendly (data residency)
| Aspect | Aurora Global | TiDB |
|---|---|---|
| Managed | Yes (AWS) | Self-hosted or TiDB Cloud |
| Multi-writer | No | Yes |
| Replication | Async (<1s) | Sync (Raft) |
| Consistency | Eventual (cross-region) | Strong |
| Failover | ~1 minute | Automatic (Raft) |
| Compatibility | MySQL/PostgreSQL | MySQL |
| Vendor lock-in | AWS | None |
-
Choose based on write pattern
- Single writer → Aurora Global (simpler)
- Multi-writer → TiDB/CockroachDB
-
Plan data locality
- Keep data close to users
- Use placement policies
-
Understand consistency trade-offs
- Sync replication = higher latency
- Async replication = possible data loss
-
Test failover
- Automate failover procedures
- Measure RTO/RPO
-
Monitor replication lag
- Alert on high lag
- Track cross-region latency