Double Entry Transition Tables: How We Track State Changes At Shopify
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.
Related posts
- The Complex Data Models Behind Shopify's Tax Insights Feature
Shopify Engineering mediumAdeptShopify's Tax Insights feature tells US merchants when they reach sales-tax economic nexus in each state. It runs on a pipeline of Spark data models over warehouse tables in GCS. State rules differ in dollar and order thresholds, inclusive or exclusive comparisons, excluded order types, and evaluation periods (prior calendar year, rolling 12 months, preceding four quarters). To handle this, the team built a rules lookup table with valid_from/valid_to dates, which drives a dimensional model of evaluation windows and thresholds per state per date. That model is joined to monthly merchant-state sales to produce a merchant-state-month liability model. The latest snapshot is pushed to Bigtable keyed by merchant ID for the app backend to serve. The team prototyped in SQL with BigQuery before PySpark, split the logic into intermediate models, and generalized the design so it later extended to Canadian GST.
- ShopifyQL Notebooks: Simplifying Querying with Commerce Data Models
Shopify Engineering mediumAdeptShopify 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. Good models are purpose-driven, explorable (right granularity, useful dimensions, fully additive metrics rather than semi- or non-additive ones) and extensible. The process runs from business questions to mock data and template queries, then to sourcing upstream tables, checking quality and consistency, and deriving freshness from upstream SLOs. Build time improved by switching from full-drop to incremental pipelines, at some cost in maintainability, and query speed improved with daily per-product roll-up tables for high-cardinality GROUP BYs.
- Capturing Every Change From Shopify’s Sharded Monolith
Shopify Engineering mediumAdeptShopify 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. Polling caps data freshness at about an hour and cannot capture hard deletes, intermediate row states, or updates that skip updated_at. It also produces snapshots with mismatched high-water marks. The new design merges per-shard Debezium output into one Kafka topic per logical table, so a single CDC pipeline can serve both the internal data warehouse and the merchant analytics platform with near-real-time change events.
- Partition Finalization in Pinterest’s Next-Generation DB Ingestion Framework
Pinterest Engineering hardMasterPinterest'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. Each Flink checkpoint records min/max event time and a mergeable t-digest percentile sketch (a few hundred bytes) in the Iceberg snapshot summary. A post-commit hook then computes a monotonic, non-regressing watermark, by default the minimum of per-commit minimums over the last X commits rounded down to the hour, and stores it as a table property that downstream sensors can wait on. The Spark upsert job copies the watermark to the base table. The work is built on generic Accumulator and CommitProcessor extension points in an extensible Flink-Iceberg sink, and tables can choose percentile-based policies to trade completeness for freshness.
- Sync Stripe Data to Your Supabase Database in One Click
Supabase mediumAdeptSupabase 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. Unlike the existing Stripe Foreign Data Wrapper, which translates each query into Stripe API calls and slows down or hits rate limits on joins and aggregations, the sync engine lets queries run against local indexed data. Example SQL shows finding unconverted signups, computing MRR by plan, and spotting inactive paying accounts. Stripe contributed JSONB storage with generated columns, cursor-based incremental sync, Connect multi-account support and a CLI to the open-source engine.