How can I distribute read requests across multiple Amazon RDS read replicas?
3 minute read
I want to distribute read requests across multiple Amazon Relational Database Service (Amazon RDS) read replicas.
You can use Amazon Route 53 weighted record sets to distribute requests across your read replicas. Within a Route 53 hosted zone, create individual record sets for each DNS endpoint associated with your read replicas. Then, give them the same weight, and direct requests to the endpoint of the record set.
For Domain Name and Comment, enter a name and a comment.
For Type, choose the Private Hosted Zone for the VPC that your read replicas are located in. Choosing a private hosted zone blocks access to the read replicas from external resources. Or, leave Type set as Public. Note: You must own the domain that you specify in the hosted zone if you specify Public.
Create the record set
After the hosted zone is created, select it, and choose Create Record Set. Use these attributes:
For Name, enter a name. You use this as the endpoint URL to access the read replicas.
Set Type to CNAME.
For TTL value, set a value that is appropriate for your needs. This determines how often each read replica receives requests.
In the Value field, paste the DNS endpoint of the first read replica.
For Routing Policy, choose Weighted.
In the Weight field, enter a value. Be sure to use the same value for each replica's record set.
Repeat these steps to create a record set for each additional read replica. Be sure that the record sets use the same name, and the same values for time to live (TTL), and for weight. This helps to distribute requests equally.
You can add more read replicas to respond to more connections or high resource use without changing your application endpoint. You can incorporate Route 53 health checks to be sure that Route 53 directs traffic away from unavailable read replicas.