---
title: "Double Entry Transition Tables: How We Track State Changes At Shopify"
description: "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."
url: "https://swe.quest/articles/double-entry-transition-tables-how-we-track-state-changes-at-shopify-0ad5df995363b923"
canonical: "https://shopify.engineering/double-entry-transition-tables-shopify"
source: "Shopify Engineering"
published: "2022-05-18"
difficulty: "medium"
kind: "Case study"
reading_minutes: 8
tags: ["data-pipelines","analytics","sql","python"]
---

# Double Entry Transition Tables: How We Track State Changes At Shopify

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-05-18, 8 min read, Case study. Original: [https://shopify.engineering/double-entry-transition-tables-shopify](https://shopify.engineering/double-entry-transition-tables-shopify)

## Summary

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. Shopify built a PySpark pipeline that merges per-attribute transition tables (Balance account status and Shopify account status) on a partition key and a sort key, forward-fills missing values, and uses a row-number index to break timestamp ties. The result answers how many merchants actively use Shopify Balance over time. New attributes can be added without rewriting downstream SQL or PySpark, at the cost of significant up-front build effort.

Written by swe.quest, not by the author.

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

## Topics

- [Data pipelines](https://swe.quest/tags/data-pipelines.md) (Data & databases)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- SQL window functions ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- PySpark basics
- transition/fact tables

## Keywords

Shopify Balance, PySpark, double entry transition tables, net\_change

## Related posts

- [The Complex Data Models Behind Shopify's Tax Insights Feature](https://swe.quest/articles/the-complex-data-models-behind-shopify-s-tax-insights-feature-49623cc993d19aef.md): Shopify Engineering · 2023-02-08 · Medium · 11 min read · Data pipelines, Analytics & OLAP, SQL, Python
  Shopify's Tax Insights feature tells US merchants when they reach sales-tax economic nexus in each state.
- [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.
- [Capturing Every Change From Shopify’s Sharded Monolith](https://swe.quest/articles/capturing-every-change-from-shopify-s-sharded-monolith-fd5db9b13b97ba9a.md): Shopify Engineering · 2021-03-12 · Medium · 23 min read · Event-driven architecture, Data pipelines, MySQL, Queues & messaging, Analytics & OLAP
  Shopify is replacing Longboat, its query-based change-data capture tool that polls MySQL replicas on an updated\_at column, with a log-based CDC platform built on Debezium, Kafka Connect and Kafka that reads the binlog from 100+ MySQL shards.
- [Partition Finalization in Pinterest’s Next-Generation DB Ingestion Framework](https://swe.quest/articles/partition-finalization-in-pinterest-s-next-generation-db-ingestion-framework-f8587191e2b11efa.md): Pinterest Engineering · 2026-09-25 · Hard · 11 min read · Stream processing, Data pipelines, Event-driven architecture, Time & clocks
  Pinterest's streaming CDC ingestion (Kafka, Flink, Iceberg, Spark) lost the implicit "partition complete" signal that batch loads provided, so it now derives a partition finalization watermark from event time.
- [Sync Stripe Data to Your Supabase Database in One Click](https://swe.quest/articles/sync-stripe-data-to-your-supabase-database-in-one-click-b7cbed62c6a06c5c.md): Supabase · 2025-12-19 · Medium · 5 min read · Payments & fintech, PostgreSQL, Data pipelines, SQL
  Supabase now offers a one-click Stripe Sync Engine integration that copies Stripe customers, subscriptions, invoices and payments into real Postgres tables, kept current via webhooks plus scheduled backfills run through pgmq-based Supabase Queues and Edge Functions with retries.

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)
