Search code examples
amazon-web-servicesamazon-rdsamazon-aurora

Why does Amazon Aurora (Postgres) RDS cluster connect all incoming connections to a single reader instance?


I have an Aurora RDS cluster setup with three reader instances and one writer instance. The cluster has two endpoints, a "reader" read-only endpoint and a "writer" read-write endpoint.

I open a database pool with 30 connections using the "reader" endpoint. I would like to see those 30 connections evenly distributed among the three reader instances. Instead it seems all 30 connections are connected to a single reader instance and the other two reader instances sit idle.

In the attached screenshot (I blanked out the ids, btw), one instance is more than enough capacity, three reader instances are not necessary. But this application does hit bursts of activity and I've seen the single reader instance get overwhelmed and the application doesn't seem to take advantage of the extra reader instances.

My question is why? Why is Amazon Aurora seemingly not using or even attempting to use the extra reader instances? Why is Amazon Aurora connecting all of my database connections to the same reader instance?

rds console image


Solution

  • From DNS endpoints - Amazon Aurora MySQL Database Administrator’s Handbook:

    Reader endpoint – Includes all Aurora Replicas in the DB cluster under a single DNS CNAME. You can use the reader endpoint to implement DNS-based random assignment of instance IP addresses to new read-only connections.

    This means that the DNS name will resolve to a random Reader each time that the DNS name is resolved.

    Since you created the 30 connections from the same computer within a short space of time, your computer probably used the cached DNS response and therefore used the same Reader.

    In normal situations, when the DNS name is resolved from different computers or when the DNS response cache expires, it will receive a different DNS response and will connect to a different Reader.