Shopify Embraces Rust for Systems Programming

An illustration of an engine with lines of code on it. On either side, two hands holding wrenches on either side turn nuts an bolts.

Shopify builds internet infrastructure for commerce to serve the needs of millions of merchants. Doing that requires building both flexible business logic and robust, high-performance systems. In addition to our commitment to Ruby for its flexibility and expressiveness, we have recently adopted Rust as our official systems programming language. As part of this, we have joined the Rust Foundation, and we’re excited about participating in the Rust community.

Systems programming is a demanding area of software engineering, and the language selected for it can have a massive impact on the success and effectiveness of systems software. A language used for these problems needs to be fast, productive, and safe. In addition, Shopify prefers community-driven open source projects when possible. 

Rust’s growing industry momentum and Shopify’s expanding base of systems programming projects made this the right time for us to standardize on Rust and join the Rust Foundation.

Systems Programming at Shopify

Since its founding, Shopify’s primary server-side application programming language has been Ruby. Ruby’s flexibility and expressiveness has allowed Shopify to develop a powerful commerce system that meets the needs of millions of merchants and hundreds of millions of buyers. Ruby was, is, and will be the first tool we reach for when building the server-side components of modern commerce.

For systems programming, such as high-performance network servers or extending Ruby with “native” code as opposed to defining business logic, Shopify developers have historically used languages including C and Go. Recently, we decided to standardize Rust as our systems programming language. Because of this, we’re working to better support Rust in our development and deployment processes, and help Shopify engineers develop expertise in Rust programming.

Why Choose Rust?

There are a number of aspects of Rust that make it an attractive choice for our systems programming language. These combine to give us confidence that Rust will be a powerful and welcome component of our software stack. Other companies might weigh different attributes of languages differently and come to a different choice; our evaluation led us conclusively to Rust.

Consistency

Shopify’s systems programming needs to cover a number of domains, and that number will likely grow over time. They include high-performance servers, Ruby extensions to improve performance or bridge to other libraries, and compiling to WebAssembly. We very much want to leverage investment in a single language into those many domains, which means identifying a language that can be used quite flexibly. The relevant types of systems programming will have a strong influence on an organization’s choice of language; we take quite a broad view of the landscape here.

Performance

Shopify needs to be able to scale efficiently and sustainably in order to support the world’s commerce. Rust provides us with predictable native-code performance, including fine control over memory usage, which makes it suitable for the lowest levels of our stack. Rust isn’t the only language that can provide or approximate this performance capability, of course. On this basis modern C++ might also be considered, or Go if the garbage collector’s allocation behavior and performance are acceptable.

Of course, while Rust has a high performance ceiling, it doesn’t inherently raise the performance floor. An application or component is not magically fast just because it was written in Rust; a programmer still needs to design and measure for performance, and we need to make sure that Rust developers at Shopify have the necessary tools to do that work easily. That support will be an important area of interest for Shopify as we engage with Rust and its community.

Community

The Rust language and ecosystem are driven by a healthy community, and we intend to participate in that community as we have with Ruby, Rails, React Native, and other open-source projects. Rust’s RFC process and governance structure provide a strong basis for inclusive, thoughtful discussions to drive the future of the language and tools. Our contributions will hopefully not only make Rust even more productive for Shopify’s uses, but also improve things for all Rust developers.

This is why Shopify is joining the Rust Foundation. We want to support Rust’s excellent governance model and maintenance of the “Rust commons”, and to bring our knowledge and perspective into the greater Rust conversation. The Rust Foundation’s work to ensure the health of the Rust community and ecosystem is essential, and we’re proud to join in their mission.

Productivity

In some circles, Rust has a reputation for being hard to learn and use, but developers within Shopify and without have found that—after an initial learning period—they are very productive and comfortable building with Rust. Rust also has a robust ecosystem of libraries (“crates”) and good tools for IDE integration, plus of course really very nice compiler error messages. The power of the type and macro systems allow for very expressive APIs and syntax, focusing developers’ energy on saying what they mean, rather than juggling a lot of state and invariants in their heads. Go also has a good reputation here, C and C++ less so.

Safety

Rust provides many facilities for having the compiler help ensure that programs are correct, including that they safely manage memory, and can be “fearlessly parallel”. As we become more sophisticated in our use of Rust, we will find more ways to use Rust’s type system and safety rules to preserve invariants in our systems. From our initial projects, we’ve found that Rust exposes more errors at compile time rather than runtime, compared to other languages we evaluated. This contributes to the “confident to deploy” sentiment that is often expressed by Rust developers. 

Of all the languages we considered, Rust came out strongly ahead on safety elements: not just memory safety in terms of lifetime management, but also eliminating most data races in parallel programs. There is room for improvements even in Rust, of course, such as static deadlock prevention, but that is true of all production languages. We believe that Rust’s commitment to static safety makes it the most likely to further this goal over the years to come. There is already interesting work in this area, such as Ferrocene.

Interoperability

Systems programming often involves interfacing with existing “native” libraries, such as those written in C. Unlike Go, Rust does not have a garbage collector, which makes it easier to plug in anywhere that C can be used. More specifically, Rust has good support for integrating with existing C code with tools such as bindgen, while crates such as rb-sys and magnus allow Rust to safely interop with Ruby. C++ integration is somewhat awkward still, but crates like cxx can help bridge the language barrier. We do not have a large C or C++ code base, outside of things like the Ruby VM proper, but this interoperation was nonetheless an important consideration for us.

What’s Next?

At Shopify we’re at the very beginning of our Rust journey. We have work to do on developing educational resources and our internal tooling, and learn how best to participate in the Rust community and ecosystem. We’re excited to be part of Rust’s mission to empower everyone to build sustainable, memory-safe, efficient software, and grateful to be welcomed into the Rust Foundation.

Mike Shaver is a Distinguished Engineer in Core Engineering at Shopify.

If building systems from the ground up to solve real-world problems interests you, our Engineering blog has stories about other challenges we have encountered. Visit our Engineering career page to find out about our open positions. Join our remote team and work (almost) anywhere. Learn about how we’re hiring to design the future together—a future that is digital by design.