karawaci.kode

2026-09-22 · 11 min

Multi-Region Deployment Strategy: Cutting Latency and Building Real Failover in 2026

Your users in Surabaya are getting 340ms API responses while users in the same BSD Serpong office building — five minutes from your data center — get 40ms. That gap is not a CDN problem. It’s an architecture problem. Multi-region deployment is the answer, and in 2026 the tooling is mature enough that “it’s too complex” is no longer a convincing excuse.

This article covers the actual strategy: where to put things, how to route traffic, how to handle failover that works under pressure, and what Terraform infrastructure looks like in practice.

Why latency matters more than uptime SLA

Everyone optimizes for 99.9% uptime. Fewer people optimize for p99 latency, which is the number that users actually feel. A service that’s up 99.9% of the time but responds in 800ms feels broken. A service that responds in 80ms with 99.5% uptime feels fast.

Multi-region deployment addresses both, but latency reduction is the immediate win. Physics does not negotiate: a request from Jakarta to a Singapore data center travels ~500km round-trip at the speed of light, giving you a theoretical floor of ~3ms. In practice, you’re at 15–30ms with a healthy network. But if your app is deployed only in us-east-1, a Jakarta user is looking at 200ms+ of pure network latency before your application code even runs.

The deployment approach I’ll describe here is active-passive with regional read replicas — a pragmatic middle ground that works for most production workloads without requiring multi-master database writes.

Region selection: don’t guess

Pick regions based on where your traffic actually comes from, not where your team is comfortable. Pull your last 90 days of logs and aggregate by source IP country/city using a GeoIP database.

For Indonesian-primary applications, the typical answer in 2026 is:

  • Primary: ap-southeast-1 (Singapore) — lowest latency to Java/Bali, best ecosystem support
  • Secondary: ap-southeast-3 (Jakarta) — AWS Jakarta launched in 2022, now mature enough for production, single-digit millisecond latency from the Tangerang/BSD/Serpong corridor
  • Tertiary: ap-east-1 (Hong Kong) — if you serve significant traffic from mainland Asia

The Jakarta region (ap-southeast-3) is the one most local teams underuse. For a B2B SaaS company with office users commuting from Karawaci or Gading Serpong, putting your primary deployment in ap-southeast-3 and failover in ap-southeast-1 is often the right call — not the other way around.

Infrastructure layout with Terraform

Structure your Terraform to treat each region as an independent deployment unit with a shared state backend:

infra/
├── modules/
│   ├── app-cluster/          # EKS cluster, node groups, security groups
│   ├── database/             # RDS with read replica config
│   └── load-balancer/        # ALB + target groups + health checks
├── regions/
│   ap-southeast-1/
│   │   ├── main.tf
│   │   └── terraform.tfvars
│   └── ap-southeast-3/
│       ├── main.tf
│       └── terraform.tfvars
└── global/
    ├── route53.tf            # DNS + health checks + routing policies
    └── acm.tf                # wildcard cert, us-east-1 for CloudFront

Each region’s main.tf calls the same modules with different variable values:

# regions/ap-southeast-3/main.tf
provider "aws" {
  region = "ap-southeast-3"
  alias  = "jakarta"
}

module "app_cluster" {
  source = "../../modules/app-cluster"

  cluster_name     = "prod-jakarta"
  region           = "ap-southeast-3"
  node_count_min   = 2
  node_count_max   = 10
  instance_types   = ["m7g.xlarge", "m7g.2xlarge"]  # Graviton3, 30% cheaper

  providers = {
    aws = aws.jakarta
  }
}

module "database" {
  source = "../../modules/database"

  identifier        = "prod-jakarta-replica"
  instance_class    = "db.r7g.xlarge"
  is_primary        = false
  replication_source = var.singapore_db_arn  # ARN of primary in ap-southeast-1

  providers = {
    aws = aws.jakarta
  }
}

Keep is_primary = true for exactly one region. The module uses this flag to determine whether to create an RDS instance or a read replica, whether to run schema migrations, and whether to enable deletion protection on the database.

Health checks that catch real failures

Route 53 health checks are the trigger for failover. The default configuration — a TCP check on port 443 — is nearly useless. Build a proper readiness endpoint:

// internal/health/handler.go
func ReadinessHandler(db *sql.DB, redis *redis.Client) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        ctx, cancel := context.WithTimeout(r.Context(), 3*time.Second)
        defer cancel()

        checks := map[string]error{}

        // Database: lightweight query, not just Ping()
        var one int
        checks["database"] = db.QueryRowContext(ctx, "SELECT 1").Scan(&one)

        // Redis: roundtrip, not just connection check
        _, checks["cache"] = redis.Set(ctx, "healthcheck", "1", 5*time.Second).Result()

        failed := []string{}
        for name, err := range checks {
            if err != nil {
                failed = append(failed, name+": "+err.Error())
            }
        }

        if len(failed) > 0 {
            w.WriteHeader(http.StatusServiceUnavailable)
            json.NewEncoder(w).Encode(map[string]any{
                "status": "unhealthy",
                "failed": failed,
            })
            return
        }

        w.WriteHeader(http.StatusOK)
        json.NewEncoder(w).Encode(map[string]string{"status": "healthy"})
    }
}

Wire this up in Route 53:

# global/route53.tf
resource "aws_route53_health_check" "jakarta" {
  fqdn              = "api-jakarta.internal.yourapp.com"
  port              = 443
  type              = "HTTPS"
  resource_path     = "/health/ready"
  failure_threshold = 2          # fail after 2 consecutive checks
  request_interval  = 10         # check every 10 seconds — default 30 is too slow

  regions = [
    "ap-southeast-1",  # Route 53 checks FROM these locations
    "ap-east-1",
    "us-west-2",
  ]

  tags = {
    Name        = "prod-jakarta-ready"
    Environment = "production"
  }
}

# Primary record: Jakarta
resource "aws_route53_record" "api_primary" {
  zone_id = var.hosted_zone_id
  name    = "api.yourapp.com"
  type    = "A"

  alias {
    name                   = module.jakarta_alb.dns_name
    zone_id                = module.jakarta_alb.zone_id
    evaluate_target_health = true
  }

  failover_routing_policy {
    type = "PRIMARY"
  }

  health_check_id = aws_route53_health_check.jakarta.id
  set_identifier  = "primary-jakarta"
}

# Secondary record: Singapore (failover target)
resource "aws_route53_record" "api_secondary" {
  zone_id = var.hosted_zone_id
  name    = "api.yourapp.com"
  type    = "A"

  alias {
    name                   = module.singapore_alb.dns_name
    zone_id                = module.singapore_alb.zone_id
    evaluate_target_health = true
  }

  failover_routing_policy {
    type = "SECONDARY"
  }

  set_identifier = "secondary-singapore"
}

With request_interval = 10 and failure_threshold = 2, failover triggers within 20–30 seconds of a real outage. With the defaults (30s interval, 3 failures), you’re waiting 90+ seconds. That’s the difference between a minor blip and a visible outage in your SLA dashboard.

Write routing: don’t let replicas accept writes

The most common mistake in active-passive setups: forgetting to enforce that writes go to the primary region at the application layer. Read replicas in PostgreSQL and MySQL reject writes at the database level with an error, but you want to fail fast before hitting the network round-trip.

// pkg/db/router.go
type DBRouter struct {
    primary  *sql.DB  // connection to ap-southeast-1 primary
    replica  *sql.DB  // connection to local read replica
    isPrimary bool    // true when this instance IS the primary region
}

func (r *DBRouter) ForWrite(ctx context.Context) *sql.DB {
    if r.isPrimary {
        return r.primary
    }
    // Cross-region write: adds ~15ms latency but ensures consistency
    return r.primary
}

func (r *DBRouter) ForRead(ctx context.Context, requireFresh bool) *sql.DB {
    if requireFresh || r.isPrimary {
        return r.primary
    }
    return r.replica
}

The requireFresh flag is the important detail. Payment confirmations, auth lookups, and inventory checks pass requireFresh: true. Product listings, user profile reads, and content queries do not.

Failover drill: measure what actually happens

The standard approach — “we have health checks configured, failover is automatic” — is not a real answer until you’ve measured what happens during the transition window.

Run this quarterly:

  1. Set the Jakarta health check to unhealthy manually (AWS console or CLI)
  2. Measure: how long until DNS propagates and traffic shifts to Singapore?
  3. Measure: what percentage of requests returned 5xx during that window?
  4. Measure: did any in-flight writes get lost?
  5. Restore Jakarta, measure time to fail back

The number you care about is item 3. With a 60-second DNS TTL and 20-second health check cycle, your transition window is 60–80 seconds. If 1% of requests fail during that window and you have 1,000 requests/second, that’s 600–800 failed requests. Is that within your SLA? Run the drill and you’ll know.

For database failover, Aurora Global Database’s managed failover drill is worth doing at least once a year — it does a real promotion with near-zero RPO, and you see exactly how your application handles the brief write blackout during promotion.

What this does not solve

Multi-region deployment does not fix slow queries, N+1 database calls, or unoptimized assets. I’ve seen teams deploy to six regions and still have 600ms API responses because each request triggers 40 database queries. Fix your application first — then deploy it close to users.

It also does not solve cold starts on Kubernetes. If your Singapore failover cluster is running at minimal capacity to save cost, the first burst of traffic after failover will trigger autoscaling, and your new nodes will take 2–4 minutes to become ready. Keep failover clusters at minimum viable warm capacity — two nodes that handle base load — not at zero.

The setup described here, for a typical Indonesian-market SaaS application, costs roughly $800–1,200/month in additional infrastructure versus single-region. The breakeven question is simple: what does one hour of downtime cost your business?

If the answer is more than $1,200, the math is already decided.

Ditulis oleh Reza Pradipta