Load balancing multiple read database on MySql / PHP / CodeIgniter Load balancing multiple read database on MySql / PHP / CodeIgniter codeigniter codeigniter

Load balancing multiple read database on MySql / PHP / CodeIgniter


Unfortunately there is no easy way of doing this. Due to the automagically managed nature of RDS, you are at the mercy of amazon and the services they provide. You have a few options though.

1. You stick with RDS and set up a round robin DNS.

This is achieved easiest through route53. You do this by creating multiple CNAME records for each of your read replicas' endpoints. eg db.mydomain.com -> somename.23ui23asdad4r.region.rds.amazonaws.comMake sure to turn on weighted routing policy and set the weight and "set ID" to the same.rinse and repeat for each read replica.

http://note.io/1agsSMB

Caveat 1: this is not a true load balancer. This is simply rolling a die and pointing each request to one of your RDS

Caveat 2: There is no way to health check your RDS instances and there is no way to auto-scale the instances either. Unless you do some crazy things with cloud watch trigger scripts to manually add and remove RDS read replicas and update route53.

2. Use a die roll in your application itself.

A really cheap and nasty approach you could try is to create a config for each of your read replicas in CodeIgniter and when you connect to the database you randomly choose one.

Caveats: Same as above but even worse as you will need to update your codeigniter config each time you add or remove a read replica.

3. Spend hours and hours porting your RDS to ec2 instances.

You move your database to EC2 instances. This is perhaps the most difficult solution as you will need to manage ALL of your database tweaking and tuning yourself. On the plus side you will be able to put them in an autoscaling group and behind an internal load balancer in your VPC


RDS cluster provides you two endpoints read and write. If you send the read traffic on read endpoint, AWS will manage load balancing for all read replicas. You can also apply a scaling policy for read replicas.

These options are available for AWS Aurora clusters.