content is dynamic, real time updates
user can customize, filter and sort
newsfeed(prioritize, hides, contents)
personal recommendations, ranking by algo
engagement metrics
user interaction notification
privacy control
reliability,TP 99.9, achieved through geo-distributed storage and multi-region replication.
Disaster Recovery: Data replication across regions with an RTO (Recovery Time Objective) of <10 minutes.
performance, 1 sec for loading
scalability?
back up and recovery
final consistency
DAU, 1.9billion
1post per user per day = 1.9 B post
4 interactions per post = 5.7 B interactions
each post = 100K, 1.9T per day for User generated contents
POST /posts
{
"userId": "12345",
"content": "Hello World!",
"media": ["image1.jpg"],
"visibility": "public"
}
GET /newsfeed/{userId}?limit=20&cursor=timestamp_1700000000&filter=videos
{
"userId": "12345",
"feed": [
{
"postId": "abcd1234",
"userId": "6789",
"content": "Exciting News!",
"media": ["video.mp4"],
"timestamp": "2025-02-15T09:00:00Z"
}
],
"nextCursor": "timestamp_1700000001"
}
POST /posts/{postId}/like
POST /posts/{postId}/comment
user_id (Primary Key)namefriends_list (Array of user_ids)following_pages (Array of page_ids)post_id (Primary Key)user_id (Foreign Key)contentmedia_urls (Array)timestampuser_id (Primary Key)feed_items (List of post_ids)last_updated (Timestamp)Content Ingestion
Feed Generation
Ranking & Personalization
Collaborative Filtering: Suggests posts based on similar user behaviors.
Content-Based Filtering: Prioritizes posts based on user preferences (e.g., past interactions).
Engagement-Based Ranking: Prioritizes highly liked/commented posts from close connections.
Diversity Mechanism: Prevents repetitive posts from dominating a feed.
Real-time Personalization: Uses reinforcement learning to adjust ranking dynamically.
Storage & Caching
Real-Time Updates
Trade-Off Balance:
CDN caching for media content.
feed generation models:
push model(fanout on write)
Precompute and store a user’s newsfeed in a Newsfeed Table.
Posts from friends/pages are pushed to followers during creation.
Low latency but requires high storage.
pull model:
The feed is generated dynamically when a user opens the app.
Uses an index of latest posts from followed users.
More scalable, but higher query load.
The ranking model evaluates:
💡 Tech Stack:
Storage & Caching Strategy
cache stategy:
user post: use cache aside or write behind depending on user's follower number
like when a influencer has 1M follower. resolve: use sharding by follower_id and write to follower's feed
enabled compression in cassandra, use lz4
set post value = null in cache with TTL = 30s
Better Personalization – AI-driven interest prediction.
Efficient Storage – Auto-delete inactive feeds. move to cold storage.
A/B Testing – Experiment with ranking models. 1% of users get the new ranking model.
If engagement drops >5%, rollback the update.
Dynamic Scaling using Kubernetes for backend services based on real-time traffic.
Strategy: Lazy Feed Computation