Using smart drivers - Amazon Aurora MySQL Database Administrator’s Handbook

Using smart drivers

The cluster and reader endpoints abstract the role changes (primary instance promotion and demotion) and topology changes (addition and removal of instances) occurring in the DB cluster. However, DNS updates are not instantaneous. In addition, they can sometimes contribute to a slightly longer delay between the time a database event occurs and the time it’s noticed and handled by the application.

Aurora MySQL exposes near-real-time metadata about DB instances in the INFORMATION_SCHEMA.REPLICA_HOST_STATUS table.

Here is an example of a query against the metadata table:

mysql> select server_id, if(session_id = 'MASTER_SESSION_ID', 'writer', 'reader') as role, replica_lag_in_milliseconds from information_schema.replica_host_status; +-------------------+--------+-----------------------------+ | server_id | role | replica_lag_in_milliseconds | +-------------------+--------+-----------------------------+ | aurora-node-usw2a | writer | 0 | | aurora-node-usw2b | reader | 19.253999710083008 | +-------------------+--------+-----------------------------+ 2 rows in set (0.00 sec)

Notice that the table contains cluster-wide metadata. You can query the table on any instance in the DB cluster.

For the purpose of this whitepaper, a smart driver is a database driver or connector with the ability to read DB cluster topology from the metadata table. It can route new connections to individual instance endpoints without relying on high-level cluster endpoints. A smart driver is also typically capable of load balancing read-only connections across the available Aurora Replicas in a round robin fashion.

The MariaDB Connector/J is an example of a third-party Java Database Connectivity

(JDBC) smart driver with native support for Aurora MySQL DB clusters. Application developers can draw inspiration from the MariaDB driver to build drivers and connectors for languages other than Java.

Refer to the MariaDB Connector/J page for details.

The AWS JDBC Driver for MySQL (preview) is a client driver designed for the high availability of Aurora MySQL. The AWS JDBC Driver for MySQL is drop-in compatible with the MySQL Connector/J driver.

The AWS JDBC Driver for MySQL takes full advantage of the failover capabilities of Aurora MySQL. The AWS JDBC Driver for MySQL fully maintains a cache of the DB cluster topology and each DB instance's role, either primary DB instance or Aurora Replica. It uses this topology to bypass the delays caused by DNS resolution so that a connection to the new primary DB instance is established as fast as possible.

Refer to the AWS JDBC Driver for MySQL GitHub repository for details.

If you’re using a smart driver, the recommendations listed in the following sections still apply. A smart driver can automate and abstract certain layers of database connectivity. However, it doesn’t automatically configure itself with optimal settings, or automatically make the application resilient to failures. For example, when using a smart driver, you still need to ensure that the connection validation and recycling functions are configured correctly, there’s no excessive DNS caching in the underlying system and network layers, transactions are managed correctly, and so on.

It’s a good idea to evaluate the use of smart drivers in your setup. Note that if a third-party driver contains Aurora MySQL–specific functionality, it doesn’t mean that it has been officially tested, validated, or certified by AWS. Also note that due to the advanced built-in features and higher overall complexity, smart drivers are likely to receive updates and bug fixes more frequently than traditional (bare bones) drivers. You should regularly review the driver’s release notes and use the latest available version whenever possible.