I am considering using Amazon RDS with read replicas to scale our database.
Some of our controllers in our web application are read / write, some of them are read-only. We already have an automated way to determine which controllers are read-only, so my first approach would be to open a connection to the wizard when a read / write controller is requested, otherwise open a connection to a read replica when a read request is only a controller.
In theory, that sounds good. But then I came across the concept of replication delay, which basically suggests that the replica can lag behind the master in a few seconds.
Imagine the following usage example:
- The browser is sent to
/create-account , which reads / writes, thereby connecting to the wizard - An account is created, the transaction is completed, and the browser is redirected to
/member-area - The browser opens
/member-area , which is read-only, and thus connects to the replica. If the replica is even slightly behind the wizard, the user account may not yet exist on the replica, resulting in an error.
How do you actually use read replicas in your application to avoid these potential problems?
Benjamin
source share