← Graph

Beware apartment-style database switching under threaded servers

takeaway 2 connections

The apartment gem's database-per-tenant switching re-establishes connections on a model class, which is not thread-safe across threads. The bug is masked on fork servers (Unicorn) and under light Puma load, but corrupts data at scale. Use Rails 6.1 horizontal sharding instead.

type
warning
takeaway Beware apartment-style database switching under threaded servers
about
Apartment tool
Specifically about the apartment gem's thread-safety issue.
takeaway Beware apartment-style database switching under threaded servers
from_talk
Warning raised while discussing database-per-tenant switching.

Provenance