Loading…
Static Typing for Ruby
2023-10-18
- Source
- Shopify
- Published
- Added to Yomu
Summary
Shopify’s Ruby monolith spans 37,000 files, 622,000 methods, and more than 2,000,000 calls, making fast feedback and stability difficult despite rigorous reviews and 150,000 automated tests. Sorbet was selected after the team evaluated requirements for gradual typing, speed, and support for Ruby and Rails features including metaprogramming, overloading, and class reopening. Its RBI files represent constructs it cannot infer, while per-file sigils allow adoption to progress without blocking development, and SorbetMetrics tracks sigils, typed calls, and method signatures. Shopify treats typing as a product, combining CI enforcement, developer support, surveys, and interviews to guide rollout and measure sentiment. The excerpt reports 80% of monolith files, including tests, at typed: true or higher, with almost half of calls and methods covered and type checking under 15 seconds on developer machines.
Context
Shopify needed faster feedback and greater stability for a rapidly changing Ruby monolith, even with rigorous code review and more than 150,000 automated tests. The team also needed a typing solution that could accommodate gradual adoption, execute quickly at monolith scale, and support Ruby and Rails features such as metaprogramming, overloading, and class reopening.
Approach / What changed
Shopify adopted Sorbet and treated static typing as a product. The team validated it on a small set of files, created RBI files for unsupported constructs, expanded coverage while monitoring performance, tracked adoption with SorbetMetrics, and supported developers through Slack, Discourse, surveys, and interviews. Sorbet runs in CI, with per-file sigils controlling strictness.
Takeaways
- Sorbet’s per-file sigils range from ignore and false to true, strict, and strong, allowing typing coverage to increase incrementally.
- SorbetMetrics measures adoption through file sigils, calls sent to signed methods, and methods with signatures.
- The monolith requires every file to be at least typed: false, while CI runs Sorbet on every pull request and fails builds containing type-checking errors.