Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 8 min read Case study easyNovice

Shopify-Made Patterns in Our Rails Apps

Shopify's Rails monolith relies on a set of in-house patterns: the dev CLI for consistent environment setup, a podded architecture that shards the full infrastructure stack by shop, and domain-driven components that share a single database with no database-level foreign keys. Migrations are periodically squashed into structure.sql, and quality is kept up as the org grows through a git-based translation platform, an open-source maintenance tasks engine built on Active Job, and Monorail, which enforces versioned Kafka event schemas with PII annotations. It is pitched as an onboarding overview for new Shopify developers rather than a detailed implementation guide.

Related posts

  • Building a Business System Integration and Automation Platform at Shopify

    Shopify Engineering mediumAdept

    Shopify replaced Mulesoft with an in-house Ruby on Rails platform for integrating internal business systems such as Salesforce, Airtable and Netsuite, because the proprietary JVM/XML tool sat outside Shopify's stack and couldn't easily reach internal services like Kafka. The platform is built around five priorities: minimal, transparent, flexible, secure and reusable. It implements them as a modular monolith of Rails Engines, single-method Actions for business logic, raw hashes instead of typed structs for data transformations, no business-data storage, and WebMock request-level tests. After a year it ran 18 integrations, had absorbed all the former Mulesoft apps, and was being used by other teams.

  • Reusing Code with React Native Packages at Shopify

    Shopify Engineering mediumAdept

    Shopify consolidated shared React Native code (login, foundational blocks) across apps like Shop, Inbox and Point of Sale into a monorepo of npm packages rather than many separate repos, mainly to cut maintenance costs. The setup combines TypeScript project references, Yarn Workspaces, Lerna for independent versioning and publishing, root-level Babel/Jest/ESLint configs, and a fixture app with custom Metro, Babel and Podfile config for hot reloading local packages. A PlopJS template generates new packages with auto-generated CI pipelines that rebuild only changed packages and their dependents, and a Gatsby site auto-generates docs from package.json metadata. Since June 2020 the repo has produced 17 packages, 10 contributed by product teams. The team is now splitting into a few thematic monorepos and plans to automate releases with conventional commits.

  • From Ruby to Node: Overhauling Shopify’s CLI for a Better Developer Experience

    Shopify Engineering mediumAdept

    Shopify rewrote its CLI from Ruby to TypeScript on Node to reduce system requirements, unify the Theme, App and Hydrogen workflows, and stay easy for internal teams to contribute to. Go and Rust were rejected despite their static binaries because few Shopify engineers know them. Node won over Ruby because its module system lets multiple versions of a transitive package coexist, which supports modular plugins. The new architecture rests on a shared @shopify/cli-kit package, custom ESLint rules, cross-OS CI testing, a monorepo, and a functional, MVC-like split of models, commands and services. It also uses Vitest unit tests, Cucumber E2E tests, and oclif plugins with hooks for dependency inversion.

  • Remove Circular Dependencies by Using Dependency Injection and the Repository Pattern in Ruby

    Shopify Engineering mediumAdept

    Shopify broke a circular dependency between an internal pricing gem and its two consumers (the Shopify Core Rails monolith and the Storefront Renderer) by applying the Repository pattern with constructor-based dependency injection. The gem defines a contract, made up of shared Schema domain objects and a PricingRepositoryInterface. Each consumer implements that interface over its own data sources and passes the instance into PricingEngine::Engine, which keeps the gem stateless and unaware of how data is fetched. Sorbet signatures and interfaces enforce the contract at the type level. Testing combines mock repositories inside the gem, unit tests for each consumer's implementation, and shared integration test scripts.

  • Horizontally scaling the Rails backend of Shop app with Vitess

    Shopify Engineering mediumAdept

    Shop app outgrew a single MySQL database despite federating tables across databases, so the team moved its Rails backend to Vitess, sharding user-owned tables by user_id into a "users" keyspace and keeping the rest in an unsharded "global" keyspace. The key enabler was a set of application-layer query verifiers that flagged missing sharding keys, cross-database and cross-shard transactions, cross-shard writes and cross-keyspace joins. They were rolled out first in dev/CI, then in log-only mode in production. Getting there also meant backfilling user_id onto billion-row tables, rewriting shard-key updates as insert-then-delete, and patching ActiveRecord associations so the sharding key reaches every query. Two takeaways: fix the data model early, and avoid cross-shard transactions because Vitess does not roll back partial commits by default.

The quest for software engineering knowledge.

Look:
Layout: