Julia López -Using Multiple Databases with Active Record - Rails World 2023

Learn how to use multiple databases with Active Record in Rails 6.1, including automatic connection switching, and discover how this feature can improve high availability, scalability, and performance.

Key takeaways
  • Rails 6.1 introduces automatic connection switching between primary and replica databases.
  • This feature can improve high availability and reduce load on primary database.
  • Automatic connection switching is not the same as load balancing, which is done at the replica level.
  • The primary database should not be the only writer database.
  • It’s important to prevent writes to the primary database in certain situations.
  • Rails 6.1 also introduces horizontal charting, which allows for automatic switching between writer and replica databases.
  • Using multiple databases can be useful in certain situations, such as when dealing with large amounts of data or multiple applications.
  • Rails provides built-in support for multiple databases through its ActiveRecord library.
  • When setting up multiple databases, it’s important to consider the configuration and connection switching.
  • Manual connection switching can be used when automatic connection switching is not possible.
  • Connection switching can be done at the middleware level or using the around_action method.
  • It’s important to test and verify connection switching in a production environment.
  • Connection switching can be used to improve the availability and performance of a Rails application.
  • When using multiple databases, it’s important to consider the security and compliance implications.
  • It’s also important to consider the backup and recovery strategies for multiple databases.
  • Connection switching can be used to improve the scalability and performance of a Rails application.
  • It’s important to test and verify connection switching in a staging or development environment before deploying to production.
  • Automatic connection switching can be used to improve the high availability of a Rails application.