Search code examples
djangoamazon-web-servicesautoscalingmaster-slaveamazon-aurora

AWS Aurora database read replica autoscaling - best practices for django project to connect your application to newly created databases?


Using AWS Aurora database service - you can configure master-slave replication and slave autoscaling (e.g. if slave CPU is higher than 75 percent - create a second slave).

Newly created database has a new endpoint (host) which is not registered by django yet.

What would be the best approach to firstly discover the newly created database and add it to a running django application?

I am thinking about pinging every X seconds using, lets say, aws cli and checking how many slaves are there. But the problem with this is if a slave is destroyed by an autoscaling group - my django application would start erroring, so an appropriate handling is also required...


Solution

  • You shouldn't be configuring each read replica's endpoint with django. You should configure it to use the reader endpoint provided by Aurora, which will load-balance the requests across all read replicas in the cluster. Then when a new read replica is added to the cluster django will automatically be using it.