Skip to content

Route53 Latency-Based Routing in Multi-Stack Active-Active Deployment

0

Issue Summary

We have a Route53 latency-based routing configuration challenge in our Active-Active failover pattern where two CDK stacks deployed sequentially create conflicting Route53 records.

Current Architecture

  • Enterprise CDK Library: Multi-Region API Failover pattern
  • Deployment Model: Active-Active with two stacks deployed sequentially
  • Regions: us-east-1 and us-west-2 (enterprise constraint)
  • Routing Policy: Latency-based routing

The Problem

When deploying Active-Active failover:

Stack A (deployed in us-east-1)

  • Monitors API in us-west-2 (targetRegion)
  • Creates Route53 latency record: api.example.com → api-us-west-2.example.com
  • Should set Region = us-west-2 for optimal latency routing

Stack B (deployed in us-west-2)

  • Monitors API in us-east-1 (targetRegion)
  • Creates Route53 latency record: api.example.com → api-us-east-1.example.com
  • Should set Region = us-east-1 for optimal latency routing

The Conflict

Both stacks attempt to create latency records for the same DNS name (api.example.com) but with different target regions. This causes Route53 deployment conflicts during sequential stack deployment.

Current Workaround vs Correct Behavior

Current Implementation (works but suboptimal):

  • Stack A sets Region = us-east-1 (deploymentRegion)
  • Stack B sets Region = us-west-2 (deploymentRegion)
  • No conflicts, but latency routing is backwards

Desired Implementation (optimal but conflicts):

  • Stack A sets Region = us-west-2 (targetRegion)
  • Stack B sets Region = us-east-1 (targetRegion)
  • Optimal latency routing, but Route53 conflict: "A latency RRSet with the same name, type and region already exists"

Impact

This affects our enterprise CDK library used by multiple teams for multi-region API deployments. We need to resolve this to provide both optimal latency routing and conflict-free deployments.

Technical Details

  • Service: Amazon Route53
  • Record Type: CNAME with Latency routing policy
  • Deployment Tool: AWS CDK
  • Conflict Error: "A latency RRSet with the same name, type and region already exists"

Code Example

Usage:

this.config.regions.forEach((region) => {
      const apiStack = this.createApiStack(region);
      const failoverRegion = region === Region.US_EAST_1 ? Region.US_WEST_2 : Region.US_EAST_1;
      const failoverStack = this.createFailoverStack(failoverRegion);
      failoverStack.addDependency(apiStack);
    });

Construct code:

private createActiveActiveRecordSet(healthCheckId: string, routingPolicy: RoutingPolicy = RoutingPolicy.LATENCY): void {
    const baseDomainName = `${this.props.subdomain}-${this.props.activeActiveConfig!.targetRegion}`;
    const domainName = this.props.isApisWildcardCertificateUsed ? `${baseDomainName}.apis` : baseDomainName;
    const cRecord: route53.CnameRecord = new route53.CnameRecord(this, 'CNameRecordFailover', {
      zone: this.hostedZone,
      domainName: `${domainName}.${this.hostedZone.zoneName}`,
      recordName: this.props.isApisWildcardCertificateUsed ? `${this.props.subdomain}.apis` : this.props.subdomain,
    });
    const recordSet: route53.CfnRecordSet = (cRecord.node.defaultChild as route53.CfnRecordSet);
    recordSet.ttl = this.props.ttlSeconds.toString();
    if (routingPolicy === RoutingPolicy.LATENCY) {
      **recordSet.region = this.props.activeActiveConfig!.deploymentRegion; // Should be targetRegion**
    } else {
      // By default, if user input is not provided, the Weight is set to 0 for all records in the group. Traffic is then routed to all resources with equal probability.
      recordSet.weight = this.props.activeActiveConfig!.weight || 0;
    }
    recordSet.setIdentifier = `${this.props.activeActiveConfig?.targetRegion}-${routingPolicy}`;
    recordSet.healthCheckId = healthCheckId;
  }

How to address this smooth without getting the record conflicts?

1 Answer
0

To address the Route53 latency-based routing conflict in your multi-stack active-active deployment, you need to modify your approach to avoid creating conflicting records while still maintaining optimal latency routing.

The core issue is that you're trying to create two latency records for the same DNS name (api.example.com) with the same region attribute, which Route53 doesn't allow. Here are solutions to resolve this:

Solution 1: Single Stack Responsibility

Modify your architecture so only one stack is responsible for creating all Route53 records:

  1. Create a separate "DNS stack" that depends on both regional stacks
  2. This DNS stack creates both latency records with the correct region settings
  3. Remove Route53 record creation from the individual regional stacks

Solution 2: Conditional Record Creation

Implement a condition that only allows one stack to create both records:

// Only create both records in the first stack to deploy
if (deploymentRegion === Region.US_EAST_1) {
// Create record pointing to us-east-1 with region=us-east-1
new route53.ARecord(this, 'PrimaryRecord', {
zone: myZone,
recordName: 'api.example.com',
target: route53.RecordTarget.fromAlias(new targets.ApiGateway(eastApi)),
region: 'us-east-1'
});

// Create record pointing to us-west-2 with region=us-west-2
new route53.ARecord(this, 'SecondaryRecord', {
zone: myZone,
recordName: 'api.example.com',
target: route53.RecordTarget.fromAlias(new targets.ApiGateway(westApi)),
region: 'us-west-2'
});
}

Solution 3: Use CloudFormation Custom Resources

Create a custom resource that checks if a record exists before attempting to create it, and skips creation if it would conflict.

The most straightforward approach is Solution 1, where you centralize DNS management in a single stack. This provides the cleanest separation of concerns and avoids conflicts entirely while ensuring optimal latency routing.

Remember that when using latency-based routing, Route53 will automatically direct users to the endpoint with the lowest latency based on historical data, and if health checks are configured, it will fail over to the next lowest latency endpoint if the primary is unhealthy.

For more detailed investigation specific to your AWS environment, I encourage you to reach out to AWS Support for detailed guidance.

Sources
Latency-based routing in private hosted zones - Amazon Route 53
Latency-based routing - Amazon Route 53
aws-cdk-lib.aws_route53 module · AWS CDK
Prevent the automatic failback with a Route 53 health check | AWS re:Post

answered a year ago

AWS
SUPPORT ENGINEER

revised a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.