I have a setup with one primary writer db and a readonly replica. I’ve looked into the autoswitching mechanism provided by rails, but it does not work for me since it decides based on the http method. We have a huge monolith and going over all endpoints to fit this technique is not viable. I would think that selecting the database based on the raw sql that would run could be feasable, taking into account transactions and how long has passed since the last write (to account for replication lag). Does this make sense? How should i approach implementing something like this? I looked into inheriting Middleware::DatabaseSelector however the context injected there always seems related to the request and not the sql.
Related topics
Topic | Replies | Views | Activity | |
---|---|---|---|---|
Automatic connection switches between primary/replica db based on SQL | 3 | 1418 | May 27, 2023 | |
Automatically switching database connections when writing | 1 | 484 | June 24, 2024 | |
[ActiveRecord][Multiple Databases] Route queries automatically | 2 | 957 | June 12, 2020 | |
Connection switching to support multiple databases is not working in Rails 6.0.0.beta3 version | 9 | 513 | April 26, 2019 | |
Questions about manual database connection switching in Rails 6 | 1 | 540 | October 4, 2020 |