---
title: "The Complex Data Models Behind Shopify's Tax Insights Feature"
description: "Shopify's Tax Insights feature tells US merchants when they reach sales-tax economic nexus in each state."
url: "https://swe.quest/articles/the-complex-data-models-behind-shopify-s-tax-insights-feature-49623cc993d19aef"
canonical: "https://shopify.engineering/complex-data-models-behind-shopify-tax-insights"
source: "Shopify Engineering"
published: "2023-02-08"
difficulty: "medium"
kind: "Case study"
reading_minutes: 11
tags: ["data-pipelines","analytics","sql","python"]
---

# The Complex Data Models Behind Shopify's Tax Insights Feature

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2023-02-08, 11 min read, Case study. Original: [https://shopify.engineering/complex-data-models-behind-shopify-tax-insights](https://shopify.engineering/complex-data-models-behind-shopify-tax-insights)

## Summary

Shopify'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.

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

- data warehouse modeling ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))
- Spark basics ([easy posts on Data pipelines](https://swe.quest/tags/data-pipelines.md?difficulty=easy))
- SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

Shopify Tax, PySpark, Google Cloud Bigtable, BigQuery, Starscream, Seamster, dbt, Google Cloud Storage

## Related posts

- [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.
- [How Shopify Built An In-Context Analytics Experience](https://swe.quest/articles/how-shopify-built-an-in-context-analytics-experience-bced6498ed610bad.md): Shopify Engineering · 2021-05-25 · Medium · 14 min read · Analytics & OLAP, Data pipelines, Product engineering, Stream processing, E-commerce
  Shopify embedded order and fulfillment metrics directly into the admin Orders page instead of keeping them in a separate Analytics section, after research showed merchants bouncing between pages to make decisions.
- [Introducing ShopifyQL: Our New Commerce Data Querying Language](https://swe.quest/articles/introducing-shopifyql-our-new-commerce-data-querying-language-ffb625f9afa12468.md): Shopify Engineering · 2022-06-22 · Easy · 11 min read · Analytics & OLAP, Language design, SQL, E-commerce
  ShopifyQL is a commerce-focused query language for Shopify Plus merchants that reorders SQL-like syntax (FROM before SHOW, BY instead of GROUP BY) and adds VISUALIZE for direct charting, COMPARE TO for period-over-period analysis without joins or window functions, and DURING for named commerce date ranges like BFCM.
- [Updating our data stack](https://swe.quest/articles/updating-our-data-stack-8fc5fea19caac0a4.md): incident.io · 2022-08-24 · Medium · 12 min read · Data pipelines, Analytics & OLAP, CI/CD, SQL
  incident.io's two-person data team reworked its BigQuery/dbt analytics stack as the company grew from 10 to 30 people.

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)
