DEV Community

myougaTheAxo
myougaTheAxo

Posted on

Design Multi-Region Architecture with Claude Code: Aurora Global DB, Route53, Failover

Introduction

Users in the US/EU accessing Tokyo servers get 200ms+ latency. Multi-region deployment with Aurora Global Database achieves P99 < 100ms globally. Let Claude Code design this architecture.

CLAUDE.md Rules

## Multi-Region Rules
- Primary: ap-northeast-1 (Tokyo)
- Secondary: us-east-1, eu-west-1
- Route53 Latency routing to nearest region
- Aurora Global: primary writes, secondary reads
- Replication lag: usually < 1 second
- RTO: < 1 minute, RPO: < 1 second data loss
Enter fullscreen mode Exit fullscreen mode

Generated Terraform

# Route53 Latency routing
resource "aws_route53_record" "api_tokyo" {
  name    = "api.myapp.com"
  type    = "A"
  latency_routing_policy { region = "ap-northeast-1" }
  set_identifier = "tokyo"
  health_check_id = aws_route53_health_check.tokyo.id
  alias {
    name                   = aws_alb.tokyo.dns_name
    evaluate_target_health = true
  }
}

# Health check: 10s interval, 3 failures = failover
resource "aws_route53_health_check" "tokyo" {
  fqdn              = aws_alb.tokyo.dns_name
  resource_path     = "/health"
  failure_threshold = 3
  request_interval  = 10
}

# Aurora Global Database
resource "aws_rds_global_cluster" "main" {
  global_cluster_identifier = "myapp-global"
  engine                    = "aurora-postgresql"
  engine_version            = "16.1"
}

# Secondary cluster (read-only)
resource "aws_rds_cluster" "virginia" {
  provider                  = aws.virginia
  cluster_identifier        = "myapp-virginia"
  global_cluster_identifier = aws_rds_global_cluster.main.id
}
Enter fullscreen mode Exit fullscreen mode
// Multi-region DB client
const IS_PRIMARY = process.env.AWS_REGION === 'ap-northeast-1';

// Reads from local region (low latency)
export async function read<T>(fn: (db: PrismaClient) => Promise<T>): Promise<T> {
  return fn(readDb); // Local replica
}

// Writes always go to primary (Tokyo)
export async function write<T>(fn: (db: PrismaClient) => Promise<T>): Promise<T> {
  return fn(writeDb); // Primary
}

// Health check with replica lag
export async function healthCheck() {
  const lag = await checkReplicaLag();
  return {
    status: lag < 10 ? 'healthy' : 'unhealthy',
    region: process.env.AWS_REGION,
    replicaLagSeconds: lag,
  };
}
Enter fullscreen mode Exit fullscreen mode

Summary

  1. Route53 Latency routing: users reach nearest region automatically
  2. Aurora Global Database: cross-region replication < 1 second
  3. Health checks: 10s interval, 3 failures -> automatic failover
  4. Secondary region reads from local replica, writes forward to primary

Review with **Code Review Pack (980 yen)* at prompt-works.jp*

myouga (@myougatheaxo) -- Axolotl VTuber.

Top comments (0)