Adopting a New Database Adapter: Trilogy
Trilogy is an open source client library for MySQL database servers. At Shopify, we’ve started to adopt the Trilogy client in our Rails applications. Here’s a quick look at why we’re adopting it, and how we’re getting there.
What’s Trilogy?
Trilogy is a client library for MySQL database servers open-sourced by our friends over at GitHub. It was open-sourced last year, along with its native Ruby binding and a corresponding Active Record adapter.
Trilogy was designed with Ruby workloads in mind: namely, it optimizes for the
RubyVM by making considerations around its handling of blocking syscalls and
minimizing its dynamic memory allocation. Outside of its architecture,
Trilogy’s minimal number of dependencies make it portable. The gem, in contrast
to its well-used counterpart mysql2, doesn’t require libmysqlclient
. This
eliminates well-known complexities from the installation process.
Why are we adopting it?
Trilogy has been used by GitHub’s Rails monolith since 2015, proving it’s a stable option for large Ruby workloads. Like GitHub, Shopify deploys many large Rails applications and we believe leveraging Trilogy can positively impact the performance of our workloads.
Bridging the gap
Trilogy shows promise for becoming an industry standard MySQL adapter, but there is some work required to bridge this gap. While the performance implications are the driving factor for its adoption, Shopify wants to be a key player in helping scale Rails—supporting Trilogy is one way to do this.
As Shopify works to adopt Trilogy, we’re discovering opportunities to strengthen its ecosystem. This has included building out unsupported features that are required by Shopify, including multi-statement support and auto-reconnects. It also includes extending supporting tooling, like building a Trilogy adapter for Semian (a resiliency framework to prevent cascading failures).
While performance is the obvious first-order effect, we’re hoping a natural second-order effect of our adoption is a more feature rich, well-documented, tooling enriched version of Trilogy.
Zooming out: Open source (and why it’s great!)
Shopify has been a proponent of open-source software (OSS): the Trilogy adoption advocates well for why. GitHub has built a solution for a more performant client library and we, as users of OSS, are beneficiaries of this. Moreover, in adopting Trilogy, we’re discovering room for new features, fixing old features, and fleshing out documentation and other tooling. The result is a stronger, more robust tool. Stay tuned for the third beneficiary, which we anticipate to be the Rails community as Trilogy evolves into the preferred option for its MySQL adapter.