Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Tropical On Rails 2026] ActiveRecord::Tenanted...

[Tropical On Rails 2026] ActiveRecord::Tenanted and SQLite

Discover Basecamp's new ActiveRecord::Tenanted gem for multi-tenant Rails apps. Learn database-per-tenant architecture with automatic data isolation. I'll share what works, current limitations, future features already mapped, and honest trade-offs from implementing this brand-new solution.

Avatar for Miguel Marcondes Filho

Miguel Marcondes Filho

April 13, 2026

Other Decks in Programming

Transcript

  1. A tenant can be an individual user, but more frequently,

    it’s a group of users, such as a customer organization, that shares common access to and privileges within the application instance. Each tenant’s data is isolated from, and invisible to, the other tenants sharing the application instance, ensuring data security and privacy for all tenants. www.ibm.com/think/topics/multi-tenant “
  2. A tenant can be an individual user, but more frequently,

    it’s a group of users , such as a customer organization, that shares common access to and privileges within the application instance. Each tenant’s data is isolated from, and invisible to, the other tenants sharing the application instance, ensuring data security and privacy for all tenants. www.ibm.com/think/topics/multi-tenant “
  3. Multi-DB Improvements • Per-database Connection Switching • Horizontal Sharding •

    Database namespaced tasks • Read-only Replicas • Handling Associations with Joins across Databases https://rubyonrails.org/2020/12/9/Rails-6-1-0-release
  4. acts_as_tenant • Isolate tenant data in a single database (Row-level

    multitenancy) • Very limited integration with the "rest of the Rails framework" apartment • Extends ActiveRecord to make dynamic connections • Pre-dates Rails thread-safe sharding model • Has a alpha version to be released with rails 8 compatibility • Very limited integration with the "rest of the Rails framework"
  5. "rest of the Rails framework" • Action Cable • Active

    Job • Active Storage • Action Mailer • Caching • View Caching
  6. • Active Job serializes record arguments as Global IDs •

    Action Cable uses Global IDs to generate unique stream channel names • Action Text uses signed Global IDs to reference attachments Error Condition Meaning MissingTenantError GID has no ?tenant= param A Global ID was created without tenant info NoTenantError No current tenant context Trying to locate a tenanted record while untenanted WrongTenantError GID tenant != current tenant Record belongs to a different tenant
  7. KEY CONCEPTS • Multi-tenancy: one application, isolated data per tenant

    • Rails Multi-DB Support: connecting to multiple databases from a single app • Vertical vs Horizontal Sharding: splitting by table vs splitting by rows/tenant • Connection Switching: Rails’ mechanism for routing queries to the right database • SQLite in Production: Rails 8’s push toward SQLite as a viable production database • Subdomain-based Routing: resolving tenant context from the request subdomain • Cross-database Associations: disable_joins, optional: true tradeoffs • Solid Queue: Rails’ default Active Job backend • Global ID: Rails’ universal object identifier (used by Action Cable, Active Job) • Rails Caching Layers: Fragment, Collection, Russian Doll, Low-level, SQL Active Storage, Action Cable, Action Mailer, Rails 8 Authentication, Read-only Replicas, Database Namespaced Tasks, Abstract Base Classes, Omakase Configuration, Foreign Key Constraints…