AWS Route 53: Weighted Routing Policy


The Weighted Routing Policy allows you to route DNS query traffic to multiple resources in proportions that you specify. By assigning a relative weight (a numerical value) to each DNS record, you can control the percentage of requests that is directed to various endpoints.
Amazon Route 53 sends traffic to a resource based on the weight that you assign to the record as a proportion of the total weight for all records in the group:
NOTE: Weights don’t need to sum up to 100%. Each record in weighted policy can have a health checks.
How It Works:
Weights Assignment: Each DNS record (e.g., IP addresses, URLs) is assigned a weight between 0 and 255 and it must have the same name and type.
Traffic Distribution: Route 53 uses these weights to determine the probability of returning each record in response to DNS queries.
Proportional Routing: The proportion of traffic directed to each resource is calculated based on the weight of that resource relative to the total weight.
Example:
Suppose you have three servers:
Server A: Weight 70
Server B: Weight 20
Server C: Weight 10
Total weight = 70 + 20 + 10 = 100
Server A will receive 70% of the traffic.
Server B will receive 20% of the traffic.
Server C will receive 10% of the traffic.
Use Cases for Weighted Routing Policy
Load Balancing Across Resources
Scenario: Distribute traffic between multiple servers or resources to balance the load.
Benefit: Improves resource utilization and application performance.
Implementation: Assign equal weights for equal distribution or proportional weights based on server capacity.
-
Scenario: Test new features or versions of an application by directing a portion of users to the new version while the rest use the stable version.
Benefit: Collect user feedback and performance data with minimal risk.
Implementation: Assign a smaller weight to the new version's DNS record.
Gradual Deployment (Canary Releases)
Scenario: Gradually roll out updates to a small subset of users before a full-scale deployment.
Benefit: Detect issues early and minimize impact on the user base.
Implementation: Start with a low weight for the new release and incrementally increase it.
Testing Infrastructure Changes
Scenario: Assess how infrastructure changes handle production traffic without affecting all users.
Benefit: Validate performance and stability under real-world conditions.
Implementation: Divert a controlled percentage of traffic to the updated infrastructure.
Resource Scaling Based on Capacity
Scenario: Allocate more traffic to resources with higher capacity or performance.
Benefit: Optimizes resource usage and cost-effectiveness.
Implementation: Set weights proportional to each resource's capacity.
Disaster Recovery and Failover
Scenario: Maintain backup resources that can receive traffic if primary resources fail.
Benefit: Enhances application availability and resilience.
Implementation: Assign a weight of 0 to backup resources, increasing it when needed.
Multi-Region Deployment
Scenario: Distribute traffic across different geographic regions.
Benefit: Reduces latency and improves user experience globally.
Implementation: Assign weights based on desired traffic distribution between regions.
Implementing Weighted Routing in Route 53
Create Hosted Zone:
Set up a hosted zone for your domain in Route 53.
Add DNS Records:
For each resource (e.g., server, load balancer), create a DNS record with the same name and type.
Example: Multiple
A
records forwww.example.com
.
Assign Weights:
In each DNS record, specify the desired weight.
The weights determine the traffic proportion.
Optional - Set Health Checks and Record ID:
Associate health checks with DNS records to ensure traffic is only routed to healthy resources.
Set alias names for your DNS record via Record ID
Save Configuration:
- Apply the changes to make them active.
Considerations When Using Weighted Routing
Health Checks:
Purpose: Ensure traffic isn't routed to unhealthy resources.
Implementation: Configure Route 53 health checks for each resource.
DNS Caching and TTL:
Impact: Changes in routing may not be immediate due to DNS caching.
Solution: Adjust the Time to Live (TTL) settings for quicker propagation.
💡Not all recursive DNS servers strictly follow TTL values. You cannot force them to update their caches, some DNS resolvers don’t respect TTLs at all and just implement their own caching policy however they wish. It may take considerable time, ranging from one to several days, for TTL updates to become effective. You may want to set the TTL to a lower value before making DNS changes such as 60 seconds, but in the real world, the common DNS TTL before making changes is to lower it to 300 seconds, and once the change is done you can set it back to 3600(1 hour) or 86,400 seconds(24 hours). [Source: Inside AWS Route53's Weighted Routing Policy by@devgrowth]
Relative Weights:
Understanding: The actual weight values are relative; it's the ratio that matters.
Example: Weights of 1 and 3 have the same effect as 10 and 30.
Monitoring and Logging:
Importance: Keep track of traffic distribution and resource performance.
Tools: Use AWS CloudWatch and other monitoring services.
Limitations
Complexity: Managing multiple weights can become complex in large-scale environments.
DNS Resolver Behavior: Some resolvers may cache DNS responses longer than expected, affecting traffic distribution.
Not Real-Time: Changes in weights may take time to reflect due to DNS propagation delays.
Practical Example
Scenario: You run an e-commerce website with servers in the US and Europe.
- Objective: Direct 70% of global traffic to the US servers and 30% to the European servers.
Implementation Steps:
US Server DNS Record:
Name:
www.example.com
Type:
A
Value: IP address of US server
Weight: 70
European Server DNS Record:
Name:
www.example.com
Type:
A
Value: IP address of European server
Weight: 30
Result:
- Route 53 routes approximately 70% of the traffic to the US server and 30% to the European server.
The AWS Route 53 Weighted Routing Policy is a powerful feature that provides granular control over how traffic is distributed to your resources. By adjusting weights, you can implement advanced traffic management strategies such as load balancing, A/B testing, and gradual deployments.
Subscribe to my newsletter
Read articles from Maxat Akbanov directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Maxat Akbanov
Maxat Akbanov
Hey, I'm a postgraduate in Cyber Security with practical experience in Software Engineering and DevOps Operations. The top player on TryHackMe platform, multilingual speaker (Kazakh, Russian, English, Spanish, and Turkish), curios person, bookworm, geek, sports lover, and just a good guy to speak with!