Lake¶
src/retrospeedlab/lake/ is the data platform. Everything that happens in RetroSpeedLab becomes an event in Kafka, a row in a Delta table and, where it matters, a decision: which ranking the site shows, which worker kinds the search gets, whether a lab change helped.
backend outbox ─┐
search events ──┼─> Kafka ─> Spark Structured Streaming ─> bronze / silver / live Delta tables
Twitch chat ────┘ └─> Airflow batch jobs ─> gold tables ─> backend (delta-rs), Grafana
Commands¶
uv run python -m retrospeedlab.lake relay src/retrospeedlab/lake/config.yaml
uv run python -m retrospeedlab.lake chat src/retrospeedlab/lake/config.yaml
uv run python -m retrospeedlab.lake topics src/retrospeedlab/lake/config.yaml
uv run python -m retrospeedlab.lake stream src/retrospeedlab/lake/config.yaml
uv run python -m retrospeedlab.lake job gold src/retrospeedlab/lake/config.yaml --dag manual --run-id first
| Command | What it does |
|---|---|
relay |
Creates missing topics, then moves the backend's outbox to Kafka; the cursor moves only after Kafka confirms |
chat |
Watches Twitch chat and publishes chat events and viewer minutes |
topics |
Creates missing topics only |
stream |
Runs the streaming job and restarts it with backoff on failure |
job |
Runs one batch job by name, as Airflow does |
lake/config.yaml holds the tuning values; the Kafka topics live once in src/retrospeedlab/topics.py and the experiments in src/retrospeedlab/experiments.py. Secrets and private addresses come from the environment.
Kafka¶
The backend writes each event to an outbox table in the same transaction as its row, and the relay publishes those older than 10 seconds: runs.live, runs.snapshots, lab.runs, lab.reports, highscores.entries, stream.exposures, promotion.*, hosts.metrics, donations.events and articles.metrics. The search and the runner publish straight to Kafka: runs.attempts, runs.steps, runs.records, runs.turn_minutes, runs.allocations, policy.rounds and lab.events. deploy/lake/EVENTS.md describes every topic and its payload.
Delta medallion¶
| Layer | Where | Holds |
|---|---|---|
| Bronze | GPU server disk | Raw events, API snapshots, external sources, replay traces |
| Silver | Object store | Cleaned entities: games, runs, splits, highscores, lab runs, PPO rounds |
| Gold | Object store | Summaries, improvement curves, experiments, bandit shares, heatmaps, humans vs AI |
| Live | Object store | One-row pulses for the site: the live run, search, policy, lab, chat |
The streaming job writes the live run every 30 seconds and bronze and silver every five minutes. The object store is a self-hosted Garage bucket that the backend reads with delta-rs.
Airflow¶
The DAGs in deploy/lake/dags/ run every job through python -m retrospeedlab.lake job, with one retry:
| DAG | When (UTC) | Jobs |
|---|---|---|
lakehouse_hourly |
Minute 10 of every hour outside 02:00–05:59 | API, silver, gold, sources, engagement, tracking |
lakehouse_nightly |
02:30 | The full rebuild, experiments, search allocation, bandit report, engagement, exports, platform, maintenance |
lakehouse_mining |
03:30 | Replays records into frame traces, re-verifies runs, builds heatmaps and humans-vs-AI tables |
Every task reports its success or failure to the backend, where a failure becomes an alert. A night job (the nightly ones and the sources, videos and maintenance beside them) that starts after 06:00 UTC fails rather than running into the day.
Quality gates¶
Every table write first validates its rows against the table's quality suite. A failed gate raises before anything is written, so the table stays as it was, the job fails, the report lands in gold.quality_failures (the stream keeps its own in gold.stream_quality_failures, so every Delta table has one writer) and the backend raises an alert.
Experiments¶
- Lab changes: each deployed lab change is compared on search hours before and after (frames saved per hour, crossing rate, record rate, verify failures). P-values are Holm-corrected across the metrics, with a minimum of data before a verdict and a sequential test that flags harm early.
- Search bandit: Thompson sampling over the search's worker kinds, with a Gamma posterior over frames saved per worker-second from the last 14 days. Each kind keeps a minimum share; a holdout of turns on the static split measures the bandit against no bandit.
- Engagement: A/B tests on the site and the stream use the same multiple-testing correction, with planned sample sizes; Thompson sampling ranks content with a minimum visibility.
The experiment results go to a Postgres database for the Grafana dashboards: Experiments, Lab runs, Machines, Promotion variants, Search bandit, Search turns and Training.
Tests¶
The Spark tests start a local Spark session with Delta and need Java 21; the rest of tests/lake runs without it.