multi-database-and-replicas
Installation
SKILL.md
Multi-Database + Replicas
Rails 6+ has first-class multi-database support. Use it to add a read replica before sharding, and to isolate concerns (analytics queries on a separate DB) before splitting services. AI agents often reach for sharding when a replica would do, or for two services when one DB with two connections would do.
The opinion
Add a read replica first. Sharding is a v0.3 / scale-out problem. Use
connects_toper ApplicationRecord-subtree (not per-action). Sticky writes are the default — a write followed by a read in the same request must hit primary (Rails handles viaApplicationRecord.connected_to(role: :writing)middleware). Monitor replica lag; route long-running reports to a read-only replica.