Skip to content

About

Layered game telemetry warehouse in MySQL and dbt: stored procedures, views, partitioning, query tuning, data quality checks, bot detection, and retention analysis on simulated data

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Game telemetry analytics in SQL: a layered warehouse in MySQL and dbt

An end-to-end analytics warehouse for the telemetry of a fictional cross-platform cooperative game. Raw data arrive from four systems in four formats, are loaded into a MySQL warehouse built in bronze, silver, and gold layers with stored procedures, views, partitioning, and tuned indexes, and are rebuilt independently in dbt on DuckDB. The two warehouses are reconciled against each other, checked against effects planted in the simulated data, and used to answer four questions a studio would ask: how players and co-op use move over time, whether a build broke stability, whether co-op players retain better, and which accounts are bots.

All data are simulated (generate/simulate_telemetry.py), so the true answers are known and the pipeline can be tested against them. No real player data are used.

What it covers

Area Where
Unifying disparate sources: nested JSON (profile service), Parquet (game server), day-partitioned gzipped JSON Lines (client telemetry, as in blob storage), CSV (store) generate/, scripts/load_bronze.py, dbt_telemetry/models/staging/
Bronze, silver, and gold layers with explicit keys and a dimensional model (dim_player, fct_session, fct_player_day) sql/01_bronze_schema.sql to sql/03_gold.sql
Stored procedures: layer builds, retention cohorts, bot detection with a robust z-score, data quality checks sql/02_silver.sql to sql/04_procedures.sql
Views for recurring questions: daily active players, build stability, store funnel sql/03_gold.sql
JSON handling in SQL: JSON_TABLE, JSON_EXTRACT, a stored generated column sql/02_silver.sql, scripts/benchmark_queries.py
Query tuning measured with EXPLAIN and timings scripts/benchmark_queries.py, results/explain/
Cost-efficient storage: range partitioning, and file formats compared by size and scan time sql/01_bronze_schema.sql, scripts/storage_costs.py
dbt models with 19 data tests (unique, not null, accepted values, relationships, and two custom tests) dbt_telemetry/
Reconciliation of the two warehouses and checks against the simulated truth tests/check_pipeline.py
Exploratory analysis and figures analysis/analysis.py, results/

Data

8,025 players (including 25 scripted bot accounts) over 60 days on five platforms, 96,238 sessions, 897,277 raw event rows, and 1,747 store purchases. The raw events contain the problems real telemetry has: 13,198 duplicated events from client retries, 867 events with no player id, 2,634 events stamped before their session started (device clock skew), and 407 sessions that never received an end time. Every record a cleaning rule removes or changes is written to dq_quarantine with its reason.

Results

Data quality and reconciliation

All seven checks in sp_run_quality_checks pass after cleaning (results/tables/dq_results.tsv), and the MySQL and dbt warehouses, built separately from the same raw files, agree exactly on event counts, clamped timestamps, sessions and crashes by build and platform, daily active players for all 300 date and platform combinations, and all 8,025 player records (results/tables/reconciliation.csv). All 19 dbt tests pass.

Query tuning

Query Design Median time Speed-up
Daily co-op level completions by platform, October 1 to 15 heap table, JSON parsed on every row 0.87 s 1x
range-partitioned by date (partition pruning) 0.20 s 4x
partitioned, plus a stored generated column for the JSON field and a covering composite index 0.028 s 31x
Day 1, 7, and 14 retention by install week one correlated EXISTS subquery per day 0.109 s 1x
one join with conditional aggregation 0.030 s 3.7x

Every design returns identical results, which the script checks. The tuned plan is a covering index range scan that never reads the table rows (results/explain/case1_tuned.txt). Exact timings vary by machine; the ordering does not.

Storage formats

Format Size Size vs CSV Dashboard query
CSV, uncompressed 85.3 MB 100% 0.187 s
CSV, gzip 13.0 MB 15% 0.489 s
JSON Lines, gzip (as received) 15.4 MB 18% 0.617 s
Parquet, snappy 15.2 MB 18% 0.006 s
Parquet, zstd 11.5 MB 13% 0.004 s

Gzip shrinks text files but makes every query decompress and parse all of them. Columnar Parquet with zstd is both the smallest and roughly 100 times faster to query, because the engine reads only the columns and row groups a query needs. For storage billed by the byte stored and engines billed by the byte scanned, that is the cost-efficient choice for the silver and gold layers, with the raw JSON kept only as an archive.

What the data say

Crash rate by build

Build 1.4.0 raised the Android crash rate from 1.9% to 8.9% of sessions (95% interval 8.1% to 9.7%) while every other platform stayed near 2%, and hotfix 1.4.1 brought Android back to 1.9%. The regression was confined to one platform, which points the engineers to Android-specific code in that release.

Retention by co-op use

Players who tried co-op in their first three days were active on 47% more of days 4 to 28 than those who did not. That comparison overstates the benefit of co-op, because more engaged players are also more likely to try co-op. Comparing players with the same number of sessions in their first three days lowers the estimate to 1.40, still above the true effect of 1.25 built into the simulation, because early session counts capture only part of a player's underlying engagement. The outcome window starts after the three-day window used to define co-op use, so that being active enough to try co-op is not counted as retention. The practical conclusion is that co-op is associated with retention, but its causal size needs an experiment, for example randomizing an invitation to co-op during onboarding.

Bot detection

sp_flag_anomalous_players scores each account's events per session minute against the median and median absolute deviation of all players, which the bots cannot distort the way they would a mean and standard deviation. At a robust z-score of 10 it flags all 25 scripted accounts and no real players (precision and recall 1.0): the bots score about 65, while the most active human scores about 9. Bots are excluded from the retention analysis.

Retention by install week (results/tables/retention_cohorts.tsv) is stable at about 44% on day 1, 35% on day 7, and 26% on day 14, and daily active players and co-op share by platform are in results/figures/daily_active_players.png.

Repository layout

generate/simulate_telemetry.py     simulated raw sources with planted, known effects
sql/01_bronze_schema.sql           raw tables, range partitioning, quarantine and DQ tables
sql/02_silver.sql                  cleaned, typed, deduplicated tables and sp_build_silver
sql/03_gold.sql                    dimensional model, sp_build_gold, analysis views
sql/04_procedures.sql              retention cohorts, bot detection, data quality checks
scripts/load_bronze.py             bulk load of the four sources (LOAD DATA LOCAL INFILE)
scripts/benchmark_queries.py       query tuning case studies with EXPLAIN and timings
scripts/storage_costs.py           storage format comparison
scripts/run_all.sh                 rebuilds everything from the seed
dbt_telemetry/                     the same warehouse in dbt on DuckDB, with tests
tests/check_pipeline.py            reconciliation and ground-truth checks
analysis/analysis.py               figures and tables
results/                           outputs: tables, figures, EXPLAIN plans

How to run

Requires Python 3.11 or later and a MySQL 8.0 or later server with local_infile enabled.

pip install -r requirements.txt
MYSQL_SOCKET=/path/to/mysql.sock bash scripts/run_all.sh

The full rebuild takes about two minutes. The dbt warehouse alone needs no server: after python generate/simulate_telemetry.py data, run cd dbt_telemetry && dbt build --profiles-dir ..

Author

Patricia K. Kamanda. Released under the MIT License.

About

Layered game telemetry warehouse in MySQL and dbt: stored procedures, views, partitioning, query tuning, data quality checks, bot detection, and retention analysis on simulated data

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages