Case study · Stack

How Shopify scaled one of the largest Rails apps in the world

Shopify runs online and in-person stores for millions of merchants. Its core is still a Ruby on Rails monolith, kept modular and split into isolated pods with sharded MySQL, running on Kubernetes in Google Cloud, with React, GraphQL and React Native on the client side.
Copy this stackshopify.com E-commerce platform · Canada · founded 2006

Language

UI library

  • Reactshopify.engineering

    Builds the Shopify admin, replacing the in-house Batman.js.

    Why: Its developer resources and tooling are much better than Batman.js's.

Full-stack framework

  • Remixshopify.engineering

    Provides data loading and routing for Hydrogen, Shopify's framework for custom storefronts.

    Why: It addresses the data loading, routing and error handling problems Hydrogen developers ran into.

Hosting

  • Google Cloudshopify.engineering

    Hosts Shopify's production workloads after the move off its own data centers.

    Why: Shopify said Google shares its values in open source, security, performance and scale.

  • Kubernetesshopify.engineering

    Orchestrates the services and pods on Google Kubernetes Engine.

    Why: Shopify had no orchestration solution, and Kubernetes, from the team behind Borg, was the most promising.

  • OpenRestyshopify.engineering

    Runs Nginx with Lua as scriptable load balancers.

Database

  • MySQLshopify.engineering

    Is the primary database, sharded so each pod holds its own shops.

    Why: Merchants are isolated from each other, which made sharding by shop work well.

  • Vitessshopify.engineering

    Scales the MySQL behind the Shop app's Rails backend horizontally.

    Why: It shards and reshards MySQL while staying mostly SQL-compatible, and Shopify wanted to keep running its own datastores.

Mobile framework

  • React Nativeshopify.engineering

    Is the default for every new Shopify mobile app.

    Why: It unifies iOS and Android on one stack and reuses the web team's React know-how.

Build and runtime

  • Buildkiteshopify.engineering

    Runs the monolith's test suite in parallel in CI.

    Why: It lets them run tests their own way, on their own hardware.

Data fetching

Backend framework

  • Ruby on Railsshopify.engineering

    Runs the core Shopify monolith, organized as a modular monolith.

    Why: The company says the Rails bet shaped how it thinks and let it ship product as fast as possible.

How they built it

The Rails bet and the modular monolith

Shopify was built on Ruby on Rails, and the company says that bet shaped how it thinks and let it ship product as fast as possible. More than a thousand developers have worked in the same codebase.

Instead of breaking it into microservices, a team started "componentization" in 2017: reorganizing code by business domain (orders, shipping, billing) and giving each component a public API and its own data. They chose a modular monolith because microservices bring their own costs, such as more pipelines, network latency and harder refactors.

Sources:shopify.engineering shopify.engineering

Pods, sharded MySQL and Vitess

MySQL has been the main database since the start. Because merchants are isolated from each other, Shopify could shard it by shop, and each pod is a fully isolated copy of Shopify with its own datastores. An early incident with a shared Redis, nicknamed "Redismageddon", set the rule of avoiding resources shared across the whole platform.

The consumer Shop app has roughly ten times more users than Shopify has merchants, so it needed a different model. In 2024 Shopify described moving its Rails backend to Vitess, which shards MySQL while keeping SQL and letting them run their own datastores.

Sources:shopify.engineering shopify.engineering

From own data centers to Google Cloud

For twelve years Shopify ran its own data centers. Starting around 2016 it moved to Google Cloud, and by March 2018 more than half of the workloads had migrated and 400+ production services ran on Kubernetes.

Shopify picked Kubernetes because it had no orchestration solution and this was the most promising one, built by the team behind Google's Borg. Kubernetes also replaced Chef and made it easy to spin up resources for new pods.

Sources:shopify.engineering shopify.engineering

Making Ruby itself faster

Rather than leave Ruby, Shopify invested in it. Its engineers built YJIT, a just-in-time compiler that shipped with Ruby 3.2, and in 2023 deployed it across the whole Storefront Renderer, the service that renders storefronts.

The result was a 5% to 10% gain in end-to-end request time in production, with memory overhead cut to about a third of the Ruby 3.1 version.

Sources:shopify.engineering

One React stack from admin to mobile and storefronts

The admin started on jQuery, prototype.js and an in-house framework called Batman.js, then moved to React and TypeScript, with GraphQL keeping business logic out of the client. In 2020 Shopify decided all new mobile apps would use React Native, since the web team's React know-how carried over and teams reported up to 99% shared code between iOS and Android.

In 2022 the Remix team joined Shopify, and Hydrogen, its React framework for custom storefronts, moved onto Remix's data loading model.

Sources:shopify.engineering shopify.engineering shopify.engineering

Also detected on their website

Found on the homepage with the open Wappalyzer rules (HTML, scripts and headers). It shows what runs in the browser, not the whole backend.

  • Cloudflare
  • HSTS
  • HTTP/3