Route 53 routing policies · Lesson 3 of 10 · 3 min read
Weighted routing
How weights work
Each record gets a weight from 0 to 255. The probability a record is returned = its weight ÷ the sum of weights of healthy records.
resource "aws_route53_record" "blue" {
zone_id = var.zone_id
name = "app.example.com"
type = "A"
set_identifier = "blue"
weighted_routing_policy { weight = 90 }
alias {
name = aws_lb.blue.dns_name
zone_id = aws_lb.blue.zone_id
evaluate_target_health = true
}
}
resource "aws_route53_record" "green" {
zone_id = var.zone_id
name = "app.example.com"
type = "A"
set_identifier = "green"
weighted_routing_policy { weight = 10 }
alias {
name = aws_lb.green.dns_name
zone_id = aws_lb.green.zone_id
evaluate_target_health = true
}
}
- Weight 0 stops traffic to a record — unless all records are 0, in which case they're returned with equal probability. Useful to keep a standby defined but idle.
- Unhealthy records are removed from the calculation (their share goes to healthy ones).
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Uses
- Gradual migration to a new stack/region/account: 90/10 → 50/50 → 0/100, watching metrics at each step.
- Blue-green at the DNS layer (0/100 flip) — with the caveat that DNS caching makes the switch slow and uneven.
- A/B testing of whole stacks.
- Spreading load across multiple regions/ALBs in fixed proportions.
Why weighted DNS is imprecise for canaries
Resolvers cache one answer and serve it to all their users for the TTL. A few large resolvers (ISP resolvers, 8.8.8.8, corporate resolvers) represent huge user populations, so the real traffic split can be far from 95/5 and moves in lumps. Some clients ignore TTL. Rollback also waits on caches. For precise canaries, split at the ALB (weighted target groups), ingress controller, or service mesh; use weighted DNS for coarse, slow shifts between whole stacks or regions.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.