Skip to content

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

Shopify Engineering 8 min read How-to mediumAdept

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

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.

Assumes: Ruby gemsObject-oriented interfaces

Related posts

  • How We Fixed the Dependency Confusion Vulnerability in Over 600 Ruby Applications

    Shopify Engineering mediumAdept

    Shopify closed a dependency confusion hole across roughly 600 Ruby applications by migrating each `Gemfile.lock` to Bundler's newer format, which pins every gem to an explicit source. A custom Bundler plugin did the upgrade without changing dependency versions: it allowed only patch updates during regeneration, then restored the original versions. A CLI running on top of CI gave each repository its own environment, ran the migrations in parallel and opened pull requests automatically. Shopify also failed CI on outdated Bundler versions and worked with the Bundler maintainers on changes that shipped in 2.2.21 and 2.2.22, the latter preventing lockfiles from regressing to the old format.

  • Shopify-Made Patterns in Our Rails Apps

    Shopify Engineering easyNovice

    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.

  • 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.

  • 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.

  • A Packwerk Retrospective

    Shopify Engineering mediumAdept

    Packwerk, Shopify's static analysis gem for enforcing package boundaries in Rails monoliths via constant references, works best as a dependency-graph tool rather than an API-privacy tool, which is why privacy checks were removed in 3.0. Its blind spots are significant: it relies on developer-drawn package graphs that often follow naming semantics rather than runtime behaviour, it gives no guidance on fixing violations, and it ignores constants loaded outside Zeitwerk as well as routes, initializers and fixtures. Isolating a zero-dependency 'Platform Essentials' package took months. Reaching zero violations was not enough, and real isolation also needed booting the package alone and running its tests in CI. Domain-based package boundaries fit poorly with how code actually runs, while function-based layering proved more workable.

The quest for software engineering knowledge.

Look:
Layout: