Sub topic 8
Routing policies: simple, weighted, latency, failover and more
This chapter assumes you can create a hosted zone and write records with change batches. It also assumes you know what a health check does. A routing policy decides which record values Route 53 returns when several records share the same name and type.
How a policy is selected
You choose a policy per record. Every record set that shares a name and type must use the same policy. Policies other than simple require a SetIdentifier, a label that tells records with the same name apart.
| Policy | Chooses an answer by | Typical use |
|---|---|---|
| Simple | Returning all values in one record | One endpoint |
| Weighted | Relative weight | Gradual rollouts, A/B tests |
| Latency | Lowest latency from the user to an AWS Region | Multi-Region apps |
| Failover | Health of the primary | Active-passive recovery |
| Geolocation | Location of the user | Content or legal restrictions |
| Geoproximity | Distance, with an adjustable bias | Shifting load between sites |
| Multivalue answer | Up to eight healthy values | Cheap client-side balancing |
Simple routing
A simple record has one name, one type and one or more values. If you list several values, Route 53 returns all of them in random order and the client picks one. Simple records cannot be attached to health checks.
Weighted routing
Each record has a Weight from 0 to 255. A record's share of answers is its weight divided by the sum of the weights. With weights 90 and 10, about 90 percent of answers go to the first record. This is the usual canary pattern.
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "app.example.com",
"Type": "A",
"SetIdentifier": "blue",
"Weight": 90,
"TTL": 60,
"ResourceRecords": [{ "Value": "192.0.2.20" }]
}
},
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "app.example.com",
"Type": "A",
"SetIdentifier": "green",
"Weight": 10,
"TTL": 60,
"ResourceRecords": [{ "Value": "192.0.2.30" }]
}
}
]
}To drain a endpoint, set its weight to 0. If every weight is 0, Route 53 treats them as equal. Keep the TTL low, because resolvers cache the answer they received and keep sending that client to the same endpoint until it expires.
Latency routing
You create one record per AWS Region, each with a Region field and a SetIdentifier. Route 53 returns the record for the Region with the lowest measured latency from the resolver's network to AWS. This is not the same as geographic distance. Add health checks so a failed Region is skipped.
Failover routing
Failover uses a pair of records, one PRIMARY and one SECONDARY. Route 53 answers with the primary while its health check passes. When it fails, Route 53 answers with the secondary.
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "www.example.com",
"Type": "A",
"SetIdentifier": "primary",
"Failover": "PRIMARY",
"TTL": 60,
"HealthCheckId": "HEALTH_CHECK_ID",
"ResourceRecords": [{ "Value": "192.0.2.40" }]
}
},
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "www.example.com",
"Type": "A",
"SetIdentifier": "secondary",
"Failover": "SECONDARY",
"TTL": 60,
"ResourceRecords": [{ "Value": "192.0.2.50" }]
}
}
]
}Replace HEALTH_CHECK_ID with the ID returned by create-health-check. Failover time is the health check detection time plus the record TTL. With a 30-second interval, three failures and a 60-second TTL, clients can take about two and a half minutes to move.
Geolocation, geoproximity and multivalue
- Geolocation maps the user's country, or US state, to a record. Always add a default record, or users from unmapped locations get no answer.
- Geoproximity routes to the nearest resource and lets you apply a bias to expand or shrink a site's reach.
- Multivalue answer returns up to eight healthy records. It improves on simple routing because unhealthy values are removed, but it is not a load balancer.
Common errors
- Omitting
SetIdentifier, or reusing one within the same name and type, so the change batch is rejected. - Mixing policies on one name and type.
- Setting a high TTL and then expecting fast failover.
- Using failover without a health check on the primary. Route 53 then assumes the primary is healthy and never fails over.
- Forgetting a geolocation default record.
Exercise
You run www.example.com in two Regions and want users sent to the faster Region, but never to a Region whose endpoint is down. Which policy and which extra setting do you use, and what must each record have?
Show answer
Use latency routing with one record per Region. Each record needs a Region value, a unique SetIdentifier and a health check (or EvaluateTargetHealth for an alias). Route 53 then skips a Region whose check fails.
Exercise
A failover primary stops responding, yet clients keep reaching it for several minutes. Name two causes.
Show answer
The record TTL is still cached by resolvers, and the health check needs several failed intervals before it marks the primary unhealthy. A missing health check on the primary would also prevent failover entirely.