Skip to content

About

ETL process for BGG cloud data warehouse

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

426 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BGG Data Warehouse

A data pipeline that collects BoardGameGeek (BGG) game data, lands it in BigQuery, and transforms it into a normalized warehouse plus analytics and ML-prediction tables for downstream consumers.

Overview

  1. Discover IDs — new game IDs are found by probing BGG's XML API2 for IDs above the current maximum and upserted into raw.thing_ids.
  2. Fetch — game data is fetched from BGG's public XML API2 and stored as raw XML in BigQuery.
  3. Process — raw responses are parsed into normalized core tables.
  4. Transform — Dataform models build the analytics and predictions datasets.
  5. Enrich — ML predictions and embeddings from the sibling bgg-predictive-models project flow in via cross-project Dataform sources, coordinated by a bidirectional repository_dispatch event chain.
  6. Consume — the analytics and predictions datasets are read by downstream apps, notably the separate bgg-viewer project. This repo is the warehouse/back end; it does not serve a UI.

For the full picture see docs/architecture.md and the diagrams under docs/architecture/diagrams/.

Architecture

Pipelines (src/pipeline/)

Pipeline What it does How it runs
fetch_thing_ids Discovers new game IDs by probing the XML API2 around the current max ID — --lookback N re-probes the N IDs below it (skipping known ones) before walking the frontier, since most newly published IDs were reserved earlier; MERGEs them into raw.thing_ids. Sitemap scraping (--source bgg_sitemap) is kept as a legacy option — it needs residential egress, see scripts/box/README.md. 06:00 UTC on GitHub Actions: lookback 500 Mon–Sat, 5,000 on Sunday. See the probe lookback spec.
fetch_new_games Fetches API responses for unfetched IDs in raw.thing_ids and processes them into core tables. After Fetch Thing IDs (or a thing_ids_fetched dispatch from the home box, if used).
refresh_old_games Re-fetches stale games based on a publication-year policy (see config/bigquery.yaml). After Run Fetch New Games completes (any conclusion), so the daily chain runs Dataform once.
fetch_games On-demand fetch/refresh of specific game IDs. Manual workflow_dispatch with a comma-separated game_ids input.

Orchestration (GitHub Actions + repository_dispatch)

The daily flow is event-driven rather than a fixed schedule:

cron 06:00 UTC ─ Fetch Thing IDs
  └─ (workflow_run) Run Fetch New Games
       └─ (workflow_run, any conclusion) Run Refresh Old Games
            └─ (workflow_run) Run Dataform ──> analytics + predictions
                 └─ repository_dispatch: dataform_complete ──> bgg-predictive-models
                        (text embeddings → complexity → scoring → game embeddings)
                 ┌───────────────────────────────────────────────┘
                 └─ text_embeddings_complete / complexity_complete / embeddings_complete
                      └─ Run Dataform (re-run to publish each ML output)
                           └─ after embeddings_complete: catalog_refresh ──> bgg-viewer

One chain, one Dataform/ML cascade per day. Refresh Old Games deliberately runs even if ID discovery failed, so existing games still get refreshed.

Pipeline Status runs daily at 12:00 UTC and reports on the last ~26h: whether each job ran, whether we searched, how many new IDs were found and fetched, and how many old games were refreshed. A finding doesn't fail the run: it opens (or comments on) an issue labelled pipeline-status, which the next clean day closes.

The whole chain (all twelve stages across the three repos), table freshness and coverage, and the live model versions are served by the warehouse API at GET /monitoring/pipeline and shown on bgg-viewer's admin /admin/pipeline page. The API needs GH_TOKEN to read Actions history (locally: GH_TOKEN=$(gh auth token)). GET /monitoring/lineage serves the Dataform lineage (latest clean compilation of main, parsed by src/monitoring/lineage.py, which the lineage action also uses) with row counts and last-modified times from BigQuery table metadata, and GET /monitoring/tables/{project.dataset.table} serves one table's schema; both back the admin Lineage page.

Key workflows in .github/workflows/:

Workflow Trigger
fetch_thing_ids.yml 0 6 * * 1-6 (lookback 500) and 0 6 * * 0 (lookback 5,000), or manual (source, lookback inputs)
fetch_new_games.yml after Fetch Thing IDs, repository_dispatch: thing_ids_fetched, or manual
refresh.yml after Run Fetch New Games (any conclusion), or manual
fetch_games.yml manual workflow_dispatch (game_ids input)
dataform.yml after Run Refresh Old Games or Run Fetch Games, repository_dispatch from the ML repo, push to definitions/**, or manual
pipeline_status.yml daily 0 12 * * *, or manual (window_hours input)
deploy.yml push to main (builds & deploys the Cloud Run jobs)
terraform.yml push/PR to terraform/**
release-please.yml push to main (keeps the release PR open; merging it tags vX.Y.Z)

Data model (BigQuery)

Dataset Managed by Contents
raw pipeline code thing_ids, raw_responses, fetched_responses, processed_responses, request_log, fetch_in_progress
core pipeline code games plus dimension (categories, mechanics, families, …), creator (designers, artists, publishers) and association (game_categories, …) tables
analytics Dataform games_active, games_features, best_player_counts, game_dropdown_options, game_similarity_search, filter_*
predictions Dataform (from bgg-predictive-models) bgg_predictions, bgg_complexity_predictions, bgg_game_embeddings, bgg_description_embeddings, bgg_game_coordinates, user_collection_predictions, game_first_prediction
staging, monitoring Dataform internal (feature hashes, deployed-model registry)

Dataform sources and cross-project declarations live in definitions/sources.js; the model lineage is in docs/lineage.md. Dataform operational notes (incremental refreshes, schema drift) are in docs/dataform_operations.md.

Infrastructure

  • Cloud Run jobs run the pipelines; they are built and deployed by Cloud Build (config/cloudbuild.yaml), not Terraform: bgg-fetch-thing-ids (8Gi / 2 vCPU), bgg-fetch-new-games, bgg-refresh-old-games, bgg-fetch-games.
  • Terraform (terraform/) manages the artifact registry, service accounts, and Secret Manager — not the Cloud Run jobs.
  • Dataform transformations run via the dataform.yml workflow.

Prerequisites

  • Python 3.12+
  • uv package manager
  • A Google Cloud project with BigQuery, Cloud Run, Cloud Build, and Dataform enabled
  • A service account with BigQuery Data Editor and Cloud Run Invoker roles

Setup

git clone https://github.com/phenrickson/bgg-data-warehouse.git
cd bgg-data-warehouse

# Install dependencies
uv sync

# Only needed for the legacy sitemap scraper (fetch_thing_ids --source bgg_sitemap) locally:
uv run playwright install chromium

# Configure environment
cp .env.example .env
# Set GOOGLE_APPLICATION_CREDENTIALS (path to your GCP service-account key) and,
# optionally, BGG_API_TOKEN. BGG's XML API2 is public — no token is required.

GitHub repository secrets used by the workflows:

  • GCP_SA_KEY_BGG_DW — GCP service-account key JSON (required)
  • BGG_API_TOKEN — optional; BGG's API needs no auth
  • CROSS_REPO_PAT — PAT used to dispatch events to bgg-predictive-models

Usage

Local development

# Run a pipeline locally
uv run python -m src.pipeline.fetch_new_games
uv run python -m src.pipeline.refresh_old_games
uv run python -m src.pipeline.fetch_thing_ids      # requires playwright chromium
uv run python -m src.pipeline.fetch_games          # reads GAME_IDS env var

# Run the tests (pytest lives in the `test` extra)
uv run --extra test python -m pytest

Manual Cloud Run job execution

gcloud run jobs execute bgg-fetch-new-games   --region us-central1 --wait
gcloud run jobs execute bgg-refresh-old-games --region us-central1 --wait

Consumers

This repo is the warehouse itself and does not serve a UI. The consumer-facing app is the separate bgg-viewer project, which reads the analytics and predictions datasets (directly and through the warehouse read API in services/warehouse_api/). See the ecosystem diagram in docs/architecture/diagrams/.

Documentation

Versioning

Semantic versioning, cut by release-please from conventional commit subjects. Every push to main updates an open release PR; merging it bumps the version, writes the CHANGELOG.md section, and creates the vX.Y.Z tag and GitHub Release.

License

MIT License

About

ETL process for BGG cloud data warehouse

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages