Shardines
lastmod 2025-04-29created 2025-04-291 edits
Managing per-tenant databases with SQLite in Rails
About
- Explains how to build a structure in Rails where each tenant uses a separate database, and the challenges involved
- ActiveRecord is designed around a single DB connection by default, so switching connections per tenant is complex and tricky
- Proposes using the connected_to feature in Rails 6+ to switch connections dynamically at runtime
- SQLite3 suits handling many small, independent DBs, making management such as backup, debugging, and deletion easy
- Emphasizes that, unlike Rails infrastructure that evolved around large-scale system optimization, an architecture centered on small, independent databases is possible