'Reading from Read Replica hosted in AWS
I have spring boot java application running in IKS and using Aurora RDS Postgres. We have write and reader replica set for database. We want to use Read replica for read only queries. Has anyone have any experience with that?
I tried using below:
https://github.com/kwon37xi/replication-datasource/blob/master/README.md
Stack trace: Cannot create inner bean '(inner bean)#1fdff2f5' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1fdff2f5': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$69437e9e]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'replicationDataSourceConfig': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'writeDataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?
Solution 1:[1]
Your RDS Cluster has two terminaison endpoints: the general one and the read one.
The general one is here to handle Write requests. The read one is here to handle Read requests.
When only one Instance is inside the cluster, the general endpoint can be used for Read and Write request.
When one Master and x Reader(s) are inside the cluster, the general endpoint will redirect to the Master Instance while the Read one will redirect to one of the Reader instances.
LoadBalancing is managed by AWS RDS Service between Reader instances.
Multi-Master instance support has been released not long ago, you should take a look if this configuration matches with your needs.
Also, notice that there is a time of synchronisation between Master and Reader instances. Sometimes, the Read instances can have some lags. Be careful if your applications Endpoint are performing chained write/read/write/read operations.
Another thing, it is highly recommended to setup every Reader instances at least as powerful as the Master one. Otherwise, if the Master handle a high throughput of requests, the Reader instances could have many lag, or crash because they could not handle the workload.
Hope it will help you!
Solution 2:[2]
You can find details explanations and working examples of using read replicas for RDS PostgreSQL in this post it should be also the same for Aurora.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Niraj Sonawane |