Active Record while_preventing_writes API versus read-only transactions

There are many reasons we implemented while_preventing_writes this way in particular that may not be obvious from the PR.

  1. Opening transactions isn’t free and can result in a lot of overhead on queries.
  2. Readonly transactions don’t play nice with some tools used at scale like ProxySQL.
  3. Both Shopify and GitHub used similar approaches in our applications to blocking writes on reading connections and we felt there was enough prior usage to justify upstreaming it.

Implementing a way to optionally use readonly transactions would be fine, but we don’t want to replace while_preventing_writes with readonly transactions.

4 Likes