Iowa Liquor Sales Analytics

Overview

Data engineering capstone for the Data Engineering Zoomcamp: an end-to-end pipeline that takes the public Iowa liquor sales dataset from BigQuery open data through a GCS/BigQuery lakehouse and into a dbt analytics layer. The stack is Terraform for infrastructure, Kestra for orchestration, dbt for SQL transformations, Docker for local services, and GitHub Actions for CI — with an architecture diagram in docs/workflow.md and a uv + Makefile developer workflow.

Dataset

Sourced from bigquery-public-data.iowa_liquor_sales.sales on Google BigQuery — an open public table containing every wholesale purchase of liquor in the State of Iowa by retailers for sale to individuals since January 2012, collected by the Alcoholic Beverages Division of the Iowa Department of Commerce. The same data is published as open data by the State of Iowa.

Ingestion (Kestra)

Two Kestra flows implement ingestion: 01_gcp_iowa_liquor is parameterized by dataset, year, and month for ad-hoc backfills, while 02_gcp_iowa_liquor_scheduled runs the same pipeline on a monthly schedule. A Python task in a Kestra pydata container queries bigquery-public-data.iowa_liquor_sales.sales, derives zip_code_int and longitude/latitude from the store_location geography column, and filters out records without a location.

The result is written as CSV to a GCS bucket, loaded into a BigQuery external table, given an MD5 composite unique_row_id (invoice + date + store + zip + vendor), and merged with MERGE ... WHEN NOT MATCHED THEN INSERT into a consolidated iowa_liquor table — making re-runs idempotent and duplicate-free. Execution files are purged afterwards, and make kestra brings orchestration up locally with docker compose.

Infrastructure (Terraform)

The Terraform configuration (terraform/) uses the Google provider to provision the GCS bucket that stages ingested files — with a lifecycle rule aborting incomplete multipart uploads — and the BigQuery dataset that holds the raw table and dbt outputs. Project, region, and credentials are parameterized through variables.

Transformations (dbt)

The liquor_data dbt project (with the dbt_utils and codegen packages) transforms the consolidated table through one staging model and twelve core models. The staging view stg_iowa_liquor de-duplicates on invoice and date with a row_number, generates a surrogate sales_id, applies type-safe casts to the numeric fields, supports a 100-row is_test_run guard, and is documented column by column in schema.yml.

Time-series and geographic analytics: monthly sales with month-over-month growth computed with lag() window functions, a four-month rolling-average sales forecast, and monthly cost-versus-retail price trajectories per item. County revenue rankings and per-store revenue aggregated to latitude/longitude with BigQuery geography functions (ST_X/ST_Y) make the results mappable.

Commercial analytics: item-level price elasticity estimated as the change in bottles sold per unit change in average retail price, store segmentation into sales and volume quartiles with ntile(4), bought-together product pairs from an invoice-level self-join (top 20), ranked top stores and categories, most popular bottle sizes, and low-access “liquor deserts” — counties with fewer than five stores. Every model states its business question in a SQL header comment, is materialized as a table, and is built through dbt build.

Quality & CI/CD

A GitHub Actions workflow (.github/workflows/ci-cd.yml) defines the CI pipeline for pushes and pull requests on main and develop: Python 3.10 with uv, dependency installation, then dbt debug, dbt deps, and dbt build with a full refresh, followed by the data-loading step (make load). The end-to-end workflow, including a Mermaid architecture diagram, is documented in docs/workflow.md.

Links