---
title: "Focus On Behavior, Not State, for a More Maintainable Codebase"
description: "When adding pre-orders and try-before-you-buy to Shopify's Purchase Options APIs, code that equated \"has a selling plan\" with \"is a subscription\" forced repeated refactors."
url: "https://swe.quest/articles/focus-on-behavior-not-state-for-a-more-maintainable-codebase-d186fd1356391a16"
canonical: "https://shopify.engineering/behavior-not-state-for-maintainable-codebase"
source: "Shopify Engineering"
published: "2022-09-01"
difficulty: "medium"
kind: "Case study"
reading_minutes: 9
tags: ["refactoring","ruby","ecommerce","system-design"]
---

# Focus On Behavior, Not State, for a More Maintainable Codebase

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-09-01, 9 min read, Case study. Original: [https://shopify.engineering/behavior-not-state-for-maintainable-codebase](https://shopify.engineering/behavior-not-state-for-maintainable-codebase)

## Summary

When adding pre-orders and try-before-you-buy to Shopify's Purchase Options APIs, code that equated "has a selling plan" with "is a subscription" forced repeated refactors. The fix was to model behavior rather than state: wrap selling plans in an object that answers questions like "has recurring deliveries?" or "is billing deferred?" (upfront/deferred/recurring × billing/delivery), so payments, delivery and inventory code ask only what they need and conditionals disappear. To shield the data team from schema churn, a separate reporting table records these traits and labels per order, acting as a translation layer between platform code and merchant-facing domain concepts.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Refactoring & migrations](https://swe.quest/tags/refactoring.md) (Engineering practices)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [E-commerce](https://swe.quest/tags/ecommerce.md) (Domains)
- [System design](https://swe.quest/tags/system-design.md) (Architecture & design)

## Prerequisites

- object-oriented design
- Ruby on Rails ActiveRecord ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))

## Keywords

Shopify, Purchase Options API, Packwerk, Ruby on Rails, selling plans, YAGNI

## Related posts

- [Redefining impact as a data scientist](https://swe.quest/articles/redefining-impact-as-a-data-scientist-ab84e5fe086a75c9.md): Figma · 2026-02-18 · Medium · 9 min read · Testing, Payments & fintech, Observability, Engineering culture, SQL
  On Figma's billing infrastructure, data science work centered on making a complex, stateful system legible and correct rather than on experiments.
- [Building a Business System Integration and Automation Platform at Shopify](https://swe.quest/articles/building-a-business-system-integration-and-automation-platform-at-shopify-ca92d2227e71ff9f.md): Shopify Engineering · 2022-04-22 · Medium · 11 min read · Ruby, System design, API design, Testing
  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.
- [Shopify-Made Patterns in Our Rails Apps](https://swe.quest/articles/shopify-made-patterns-in-our-rails-apps-92bda4387ca54f09.md): Shopify Engineering · 2021-07-13 · Easy · 8 min read · Ruby, Developer productivity, Distributed databases, System design, Schema migrations
  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.
- [ShopifyQL Notebooks: Simplifying Querying with Commerce Data Models](https://swe.quest/articles/shopifyql-notebooks-simplifying-querying-with-commerce-data-models-518ab97f2ab79e6a.md): Shopify Engineering · 2023-02-14 · Medium · 11 min read · Analytics & OLAP, Data pipelines, E-commerce, Performance engineering
  Shopify built commerce data models behind ShopifyQL Notebooks so merchants can query metrics like sales and view-to-purchase conversion without SQL or joining across departmental datasets.
- [Double Entry Transition Tables: How We Track State Changes At Shopify](https://swe.quest/articles/double-entry-transition-tables-how-we-track-state-changes-at-shopify-0ad5df995363b923.md): Shopify Engineering · 2022-05-18 · Medium · 8 min read · Data pipelines, Analytics & OLAP, SQL, Python
  Double entry transition tables record each state change as two rows, a -1 row for the previous state and a +1 row for the new state, so counting entities in any state reduces to summing a net\_change column.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
