---
title: "Refactoring Legacy Code with the Strangler Fig Pattern"
description: "Shopify’s Ruby on Rails Shop model had grown beyond 3,000 lines, accumulated numerous responsibilities, and developed weak semantic boundaries, making store settings a target for extraction. The team used Flog’s ABC-based score—assignments, branches, and calls—to identify a particularly disordered area, then applied Martin Fowler’s Strangler Fig Pattern to move the locked_settings behavior into Capital::SettingsToLock and a dedicated record/data source. The seven-step process defined and tested a new interface, redirected callers, introduced and backfilled the new data source, switched reads, and finally stopped legacy writes and removed the old column and code. Keeping the old system available during the transition supported incremental changes, monitoring, reversibility, and the stated no-downtime requirement; the completed example left the new system in place with legacy remnants removed."
---

# Refactoring Legacy Code with the Strangler Fig Pattern

[Shopify](https://yomu.fyi/company/shopify) · 2023-10-18 · Mar 11, 2020

**Type:** Problem & solution

## Summary

Shopify’s Ruby on Rails Shop model had grown beyond 3,000 lines, accumulated numerous responsibilities, and developed weak semantic boundaries, making store settings a target for extraction. The team used Flog’s ABC-based score—assignments, branches, and calls—to identify a particularly disordered area, then applied Martin Fowler’s Strangler Fig Pattern to move the locked\_settings behavior into Capital::SettingsToLock and a dedicated record/data source. The seven-step process defined and tested a new interface, redirected callers, introduced and backfilled the new data source, switched reads, and finally stopped legacy writes and removed the old column and code. Keeping the old system available during the transition supported incremental changes, monitoring, reversibility, and the stated no-downtime requirement; the completed example left the new system in place with legacy remnants removed.

## Context

The Shop model in Shopify’s Ruby on Rails monolith had grown beyond 3,000 lines, with numerous responsibilities and weak semantic boundaries. Flog identified store settings, including locked\_settings, as a particularly disordered area. Extracting this behavior needed to account for widespread references, uncertain modelling decisions, reversibility, and a no-downtime requirement.

## Approach / What changed

The team used the Strangler Fig Pattern to incrementally extract locked\_settings into Capital::SettingsToLock and a dedicated data source. They defined and tested an interface, redirected callers, created and populated the new data source, backfilled existing records, switched reads, stopped writes to the old source, and removed the legacy code and column.

## Takeaways

- Flog uses assignments, branches, and calls to identify areas where code quality is suffering most.
- The migration keeps the old system in place while the new interface and data source are introduced, populated, and verified, allowing incremental changes and monitoring.
- The completed extraction removed locked\_settings-related code from Shop and deleted the old database column after the new system was operating.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Refactoring](https://yomu.fyi/topic/refactoring), [Ruby on Rails](https://yomu.fyi/topic/ruby-on-rails)

- Source: [Shopify](https://shopify.engineering/refactoring-legacy-code-strangler-fig-pattern)
- Source URL: https://shopify.engineering/refactoring-legacy-code-strangler-fig-pattern
- Ingested by Yomu: 2026-08-31T01:13:04.732Z

[Read original post](https://shopify.engineering/refactoring-legacy-code-strangler-fig-pattern)
