Using Multiple Databases with Active Record
summary
Rails 6’s native multiple-database support replaces an old gem and is used at Harvest after a June 2020 upgrade; production runs one primary and six replicas (four serving production), with Percona MySQL, ProxySQL for replica load balancing and Orchestrator for failover. Code uses a database.yml with primary/replica roles, middleware resolver for automatic connection switching, session- or header-based context and an around_action concern for API routing; also uses prevent_writes checks. A deploy bug (reordered includes) briefly broke routing to replicas.
AI-written summary · about
chapters (15)
- 0:00Introduction to rails
- 3:07Overview of multiple databases
- 4:29Database concepts and types
- 6:49High availability strategies
- 8:46Sharding and security
- 11:22Implementing in rails
- 13:03Rails 6 native support
- 15:27Code configuration
- 17:28Connection switching
- 18:55Automatic swapping
- 20:47Read/Write separation
- 22:28Middleware implementation
- 24:50Context and API usage
- 27:26Controller concerns
- 29:08Results and conclusion
related talks
11mMultiple Backend DBs In A Rails Application
01h 52mBuild High Performance Active Record Apps
39mPostgres & Rails 6 Multi-DB: Pitfalls, Patterns, Performance
01h 09mAll the Things I Thought I Couldn't Do
56mScaling Rails API to Write-Heavy Traffic
01h 52mBuild High Performance Active Record Apps
14mDatabase Performance at Scale for RoR Applications
41mKeynote: Technically, a Talk
