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_to per 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 via ApplicationRecord.connected_to(role: :writing) middleware). Monitor replica lag; route long-running reports to a read-only replica.

Core patterns

Pattern 1: Primary + replica config

Installs
1
GitHub Stars
21
First Seen
Sep 8, 2026
multi-database-and-replicas — sandeepmvl/rails-skills