Notes on AWS RDS Aurora replication: Use of DNS

As a newer developer to working with backend and infrastructure resources, it’s the first time that I’m doing things in AWS at scale. For example, I have never used AWS RDS Aurora before, as my databases had usually just been Linux applications running on a small EC2 instance.

I found an AWS Aurora database cluster to be fairly straightforward — it was a simple matter of working with a full DNS hostname like mydbcluster.cluster-123456789012.us-east-1.rds.amazonaws.com:3306 instead of merely connecting to localhost.

The harder part for me to understand was Aurora’s replication functionality, which provides for redundancy and higher capacity for reads and writes on the database shared across the entire cluster. While I understood what AWS was offering, it wasn’t clear to me exactly how RDS would execute load sharing or failure recovery for the cluster.

It turns out that RDS achieves this by adjusting the DNS record for the cluster’s main endpoints to point via CNAME to each of the cluster’s associated instances with a very short time-to-live value — usually 5 seconds by my experiments.

First:

; <<>> DiG 9.10.6 <<>> app-auroracluster-skddfgkhkhh.cluster-ro-dlgihlj45k3.us-east-1.rds.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60078
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;app-auroracluster-skddfgkhkhh.cluster-ro-dlgihlj45k3.us-east-1.rds.amazonaws.com. IN A

;; ANSWER SECTION:
app-auroracluster-skddfgkhkhh.cluster-ro-dlgihlj45k3.us-east-1.rds.amazonaws.com. 5 IN CNAME b0rhuiosrh09.dlgihlj45k3.us-east-1.rds.amazonaws.com.
b0rhuiosrh09.dlgihlj45k3.us-east-1.rds.amazonaws.com. 5 IN A 10.73.105.54

Then later:

; <<>> DiG 9.10.6 <<>> app-auroracluster-skddfgkhkhh.cluster-ro-dlgihlj45k3.us-east-1.rds.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 60078
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;app-auroracluster-skddfgkhkhh.cluster-ro-dlgihlj45k3.us-east-1.rds.amazonaws.com. IN A

;; ANSWER SECTION:
app-auroracluster-skddfgkhkhh.cluster-ro-dlgihlj45k3.us-east-1.rds.amazonaws.com. 5 IN CNAME vhdhelfkltj.dlgihlj45k3.us-east-1.rds.amazonaws.com.
vhdhelfkltj.dlgihlj45k3.us-east-1.rds.amazonaws.com. 5 IN A 10.73.104.227

This is so cool! With this, RDS is taking advantage of the functionality of the DNS system to achieve these goals. As someone building applications on top of RDS, this means I get to take advantage of these features with no development work on my end, which is always nice when you’re working with a new system.