AWS aurora in serverless mode can be configured with replicas to improve failover speeds
Unlike a traditional database replica which are used to switchover when the primary replica. Aurora replica are available for read queries. If we can connect to read url then we can shift the read load to replicas and improve the overall performance.
The process of connecting to a different urls for read and write introduce some context switching in connection pools. Having two separate connection pools is the recommended approach of from aws when using of @Transactional(readOnly = True). Reference aws repo.
The Gist of the approach is as follows
Create two datasource using
ConfigurationPropertiesannotationUse the
AbstractRoutingDataSourceto switch between Reader/WriterMark it as primary so that Liquibase uses it.
Create a annotation which can be weaved around methods and flips to reader if enabled
Annotate your calls to use readonly datasource instead of transaction=read-only


