Feed Ranking Architecture & Operations (Part 5 of 6)

Part 5 of 6 | ← Part 4: Ethics & Safety | Part 6: Advanced Topics → Case Study: Feed Ranking Architecture The following synthesizes public disclosures from major platforms (Meta, TikTok, YouTube, Twitter/X) into a representative architecture. Request Flow sequenceDiagram participant Client participant Gateway participant Retrieval participant Ranking participant Reranking participant Collator Client->>Gateway: Feed request Gateway->>Retrieval: Get candidates (user_id, context) Retrieval-->>Gateway: 5000 candidates Gateway->>Ranking: Score candidates Ranking-->>Gateway: 500 scored items Gateway->>Reranking: Apply diversity, policy Reranking-->>Gateway: 100 items Gateway->>Collator: Mix organic + ads + notifications Collator-->>Gateway: 50 items Gateway-->>Client: Feed response (paginated) Component Details Component Implementation Retrieval Two-tower model (user/item embeddings) + graph-based (friends’ posts) + trending Ranking Multi-task DCN with 100+ features; outputs P(click), P(like), P(share), P(hide), E(watch_time) Re-ranking MMR for diversity; policy filters; creator frequency caps Feed Collator Interleaves organic posts, ads (from separate auction), and system notifications Latency Budget Stage Target Latency (P99) Feature fetch 10 ms Retrieval 30 ms Ranking (500 items) 50 ms Re-ranking 10 ms Total < 150 ms Caching, precomputation, and model optimization keep end-to-end latency within budget. ...

July 10, 2024 · 8 min · 1539 words · Svein Erik

Recommendation Systems in Production (Part 3 of 6)

Part 3 of 6 | ← Part 2: Ranking | Part 4: Ethics & Safety → Evaluation and Metrics Recommendation systems require rigorous evaluation across offline, online, and long-term dimensions. Offline Metrics Metric Definition Use Case AUC-ROC Area under ROC curve for engagement prediction Pointwise model quality Log-loss Cross-entropy of predicted probabilities Calibration quality NDCG@k Normalized discounted cumulative gain at rank k Ranking quality Recall@k Fraction of relevant items in top-k Retrieval coverage Hit Rate Whether the engaged item appears in top-k Retrieval success Offline metrics use held-out interaction logs; they are necessary but not sufficient for production decisions. ...

July 10, 2024 · 27 min · 5544 words · Svein Erik

Social Media Platform Architecture at Scale

Modern social media platforms serve billions of users with sub-second latency requirements while handling massive write throughput and complex relationship graphs. This article examines the systems architecture required to build an Instagram or Facebook-scale platform, analyzing the mathematical models, algorithmic optimizations, and distributed systems patterns that enable performance at scale. Building a social media platform that can scale to billions of users is one of the most challenging problems in distributed systems. Unlike e-commerce sites with predictable traffic patterns or enterprise applications with controlled user bases, social platforms face extreme challenges: viral content creates massive traffic spikes, the social graph creates complex data dependencies, and user expectations demand instant updates. When Kim Kardashian posts a photo, millions of users want to see it within seconds—the system must handle this gracefully while simultaneously serving billions of other requests. ...

October 8, 2023 · 30 min · 6219 words · Svein Erik

Building a Time Series Database in Go

Time series databases (TSDBs) are specialized storage engines optimized for time-stamped data at massive scale. Unlike general-purpose databases, TSDBs exploit temporal locality, high write throughput, and read patterns dominated by range queries and aggregations. This article explores the architecture, algorithms, and implementation techniques for building a production-grade TSDB in Go, examining both storage and query engines with mathematical analysis of performance characteristics. Modern observability platforms like Prometheus, Grafana, and Datadog rely on time series databases to handle billions of metrics per second. These systems face unique challenges: metrics arrive continuously at high velocity, queries scan large time ranges for trend analysis, and storage costs must remain manageable despite exponential data growth. A general-purpose database like PostgreSQL or MongoDB would struggle under this workload—the access patterns are fundamentally different from transactional (OLTP) or analytical (OLAP) systems. ...

June 11, 2023 · 44 min · 9276 words · Svein Erik