Meta's feed ranking system makes billions of predictions daily. Every prediction
generates a ranking_event that captures the model's score and the actual user
engagement outcome.
ranking_events (
event_id VARCHAR(64) PRIMARY KEY,
user_id VARCHAR(64),
content_id VARCHAR(64),
model_version VARCHAR(50), -- 'feed-v1.2.1', 'feed-v1.3.0', etc.
score DECIMAL(5, 4), -- model's predicted engagement probability (0.0-1.0)
predicted_engagement_rate DECIMAL(5, 4),
actual_engaged INTEGER, -- 1 if user engaged, 0 otherwise
latency_ms INTEGER, -- milliseconds to compute ranking score
timestamp TIMESTAMP
)
Write a SQL query that computes daily model performance metrics for the last 7 days:
Output: date, model_version, predictions (count), engagements (count),
engagement_rate_pct, avg_predicted_rate, calibration_score, p50_latency_ms
The calibration_score is the fraction of predictions where the prediction error
(|predicted_engagement_rate - actual_engaged|) is < 0.1.
Order by date DESC, model_version ASC.