Design LinkedIn's Trending Shared Articles System (Twitter Trending analogy)

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-03-27

Problem Statement

On LinkedIn, users frequently share, like, and comment on articles. The platform wants to build a Trending Articles System (similar to Twitter Trends) that identifies which articles are gaining popularity in real time and displays them to users based on relevance, geography, and network.


✅ Functional Requirements


1.Ingestion of Article Events
•Capture every share, like, and comment related to an article.
•Deduplicate links (short URLs → canonical URL).
2.Trending Detection
•Identify “trending” articles based on:
•Velocity (rate of shares/likes over time, not just total count).
•Recency (recent interactions weighted higher).
•Diversity (shares from many unique users/companies).
3.Ranking & Personalization
•Rank trending articles globally.
•Provide personalized trends per user based on:
•Location (country, region).
•Industry/Domain (tech, finance, healthcare).
•Network (connections & followers).
4.Serving Layer
•Provide APIs for:
•GET /trending/global
•GET /trending?location=India
•GET /trending?industry=Software
•GET /trending/personalized/{user_id}
5.UI Integration
•Show a “Trending Articles” widget on homepage & search.


❌ Non-Functional Requirements


•Low Latency: New trends must appear within 1–2 minutes of activity spikes.
•Scalability: Handle hundreds of millions of events/day.
•Accuracy: Detect “real trends” and filter spam/clickbait.
•Freshness: Ensure results reflect most recent activity.
•Geo-distribution: Support localized trends worldwide.


🧱 System Components


1.Event Ingestion Layer
•Collects signals: shares, likes, comments, reshares.
•Published into Kafka (or Pulsar) topics.
2.URL Normalization Service
•Expands shortened URLs, extracts canonical URL (with OpenGraph metadata).
•Ensures different formats of the same article map to one ID.
3.Stream Processing (Trend Detection Engine)
•Uses sliding time windows (e.g., last 10 min, last 1 hr) to compute:
•Share velocity = #shares / time window.
•Weighted activity score = α*shares + β*likes + γ*comments.
•Detects spikes using algorithms (e.g., Z-score anomaly detection, Count-Min Sketch for frequency).
4.Storage Layer
•Hot Storage: Redis / Memcached for top-k trending articles in last 5–15 min.
•Historical Storage: Cassandra / HBase for aggregated article metrics.
5.Ranking Service
•Applies machine learning or heuristic scoring for trending rank.
•Considers user attributes for personalization (industry, network, location).
6.Serving API Layer
•REST APIs to serve global & personalized trends.
•Uses CDN + caching for popular queries.


🔄 Example Flow


1.User shares an article → Event logged → Published to Kafka.
2.Stream processor consumes event → Normalizes URL → Updates per-article counters.
3.Sliding window detects spike in shares for https://techcrunch.com/ai-news.
4.Ranking service boosts article based on velocity + recency + diversity.
5.API populates “Trending Articles” widget for users in Tech industry in India.


⚖️ Trade-offs / Design Considerations


•Window size trade-off: Smaller windows = more real-time but noisy; larger windows = smoother but less fresh.
•Global vs Personalized trends: Personalized trends need per-user relevance scoring → higher compute cost.
•Storage choice: Need fast writes (Cassandra, DynamoDB) + in-memory top-k (Redis).
•Spam & Abuse Prevention: Must detect fake accounts trying to make an article “trend”.
•Cold-start problem: New articles may trend slower; consider early-velocity boosting.


🧪 Open Discussion Points


•Should trending be network-first (what my connections are sharing) vs global-first (what everyone is sharing)?
•How do we decay old articles (e.g., last week’s viral post shouldn’t trend today)?
•Should we incorporate engagement quality (comments length, sentiment) rather than just counts?
•Can we extend system to also trend videos, job posts, or research papers beyond articles?


👉 This problem is a mix of real-time stream processing, ranking, personalization, and spam detection, very common in LinkedIn/Twitter/Facebook-style system design interviews.

Solution

Comments