After studying this material, you should be able to:
Before understanding the solution, you need to understand the pain.
Three different teams at a company each build their own "engagement metric." Each uses slightly different SQL. None knows the others exist. When leadership asks "How is engagement?" — they get three different answers.
| Problem | Real-World Impact |
|---|---|
| Hand-built pipelines | Slow, weeks to create |
| No monitoring | Breakages found too late |
| No shared catalog | Duplicate metrics everywhere |
| No source of truth | Metadata drifted, trust eroded |
A metric nobody trusts is worse than no metric at all.
The entire Metrics Board system rests on one central idea:
Define a metric ONCE → Metrics Board handles everything else
Using a YAML file stored in Git, treated like production code:
metric_id: mb__metrics
display_name: Metrics Board metrics count
description: Count of metrics defined in MB
metric_sql: |-
SELECT COUNT(urn) as mb_metrics, '{end_date}' as dt
FROM query_analytics.pincat_db_latest_state_v2
WHERE dt = '{end_date}'
temporal_columns:
- column_name: dt
granularity: DAY
integrations:
superset:
enabled: true
compute:
schedule: 0 9 * * * # runs daily at 9am
Think of Metrics Board as a pipeline with five stations:
[1. INVENTORY] → [2. COMPUTE] → [3. QUALITY] → [4. PUBLISHING] → [5. SERVING]
Define it Run it Validate it Distribute it Find & use it
What it does: Stores every metric definition in one place.
Key design decision:
Should Metrics Board enforce a strict data model (semantic layer), or accept any SQL?
Pinterest chose flexible SQL over a rigid semantic layer.
Why?
How users create metrics:
What it does: Turns each metric definition into a running data pipeline.
The mechanism:
YAML Definition
↓
Metrics Board reads metadata
↓
Auto-generates an Airflow DAG (scheduled workflow)
↓
Compiles SQL → SparkSQL or PrestoSQL
↓
Analyzes SQL dependencies (using sqlglot parser)
↓
Waits for upstream data → Runs → Stores results
Key benefits of one DAG per metric:
Business impact:
What used to take days or weeks now takes 1–2 hours
What it does: Validates every metric run using two complementary engines.
Explicit, human-defined expectations:
| Check Type | Example |
|---|---|
| Day-over-day | Today's value shouldn't drop >20% vs yesterday |
| Week-over-week | Compare same day last week |
| Custom threshold | Value must always be > 0 |
| Parent metric comparison | Sub-metric shouldn't exceed parent |
Learns the metric's historical patterns:
Why both? Rules catch known problems. ML catches unexpected ones that no rule anticipated.
Each metric gets a quality report containing:
What it does: Sends metric data to every tool that needs it — automatically.
The key insight: Turning on a new surface requires only one flag change:
integrations:
superset:
enabled: true # ← flip this, metric appears in Superset
starrocks:
enabled: true # ← flip this, metric appears in StarRocks
Where metrics publish:
| Destination | Purpose | When |
|---|---|---|
| PinCat (DataHub) | Data catalog, lineage tracking | At commit (before first run) |
| Helium | Experimentation platform | At commit (before first run) |
| Superset | BI dashboards | After each compute run |
| StarRocks | Fast interactive queries | After each compute run |
Two-phase publishing explained:
What it does: Makes metrics findable and signals which ones to trust.
Unknown → C → B → A → A+
↑
Manually verified by
Data Quality Steward
Each grade requires progressively more quality work. Consumers know exactly what they're getting.
| Tier | Use Case | Retention | Performance | Documentation |
|---|---|---|---|---|
| Tier 1 | Company-critical | Protected forever | Priority cluster | Full, certified |
| Tier 2 | Team-level | Retained while used | Standard | Basic ownership |
| Tier 3 | Exploratory/test | Auto-deleted when unused | Standard | None required |
Practical effect: Tier drives three automatic behaviors — how long it lives, how fast it runs, and what documentation it must have.
This is where the architecture pays an unexpected dividend.
Structured metadata + Trusted definitions + Quality signals
↓
Machine-readable, governed data
↓
Agents can reason over it reliably
User asks agent: "What was our engagement last quarter?"
Agent → queries MCP server → finds certified engagement metric → reads its SQL definition → references golden queries → returns grounded, trustworthy answer
The work done to make metrics trustworthy for humans is exactly what makes them usable by agents.
Governance isn't just bureaucracy — it's the foundation for AI reliability.
Data Producer (analyst/engineer)
↓
Fills out UI form
↓
YAML generated + PR opened
↓
Code review + merge
↓
┌─────────────────────────────────┐
│ IMMEDIATELY (metadata phase): │
│ • Cataloged in PinCat │
│ • Available in Helium (expts) │
└─────────────────────────────────┘
↓
Airflow DAG auto-generated
↓
Scheduled run executes SQL
↓
Quality checks run (rules + ML)
↓
┌─────────────────────────────────┐
│ AFTER COMPUTE (data phase): │
│ • Published to Superset │
│ • Published to StarRocks │
│ • Quality report updated │
└─────────────────────────────────┘
↓
Consumers discover via PinCat
Agents query via MCP server
Experiments use via Helium
| Concept | One-Line Summary |
|---|---|
| Single source of truth | One YAML definition drives everything |
| Isolation | One DAG per metric prevents cascading failures |
| Two-engine quality | Rules catch known issues; ML catches unknown ones |
| Two-phase publishing | Metadata publishes at commit; data publishes at compute |
| Two trust signals | Metric grades + Dashboard tiers |
| Agent readiness | Governance for humans = usability for AI |