← Graph

Database-Level Partitioning

concept 2 connections

Most extreme partitioning level: each tenant gets a completely separate database. In MySQL a database and schema are synonymous, so the schema-level caveats apply. In Postgres, switching databases requires re-establishing the connection (a new connection pool). The apartment gem implemented this by remembering the previous connection, establishing a new one, then restoring — which looks like it works but is not thread-safe: re-establishing a connection on a widely-used model doesn't propagate to other threads. Issues are masked under fork servers like Unicorn (single process) and only appear under threaded servers like Puma under load. Benefits: unlimited scale, compliance with regional data-sovereignty laws (HIPAA, PCI, EU data residency). Should today be implemented via Rails 6.1 horizontal sharding rather than apartment-style switching.

category
pattern
about
Database-Level Partitioning concept
Third partitioning level covered.
tool Apartment
related_to
Database-Level Partitioning concept
Apartment also supported database-per-tenant via connection re-establishment.

Provenance

Read by
6 extractions