Skip to main content

Design a Social Media News Feed

Design a social media news feed system with fan-out strategies, ranking algorithms, real-time updates, and content moderation.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a principal engineer at a social media company. Design a news feed system for a platform with 500 million users where 40% are daily active.

Step 1: Define the core requirements: users can create posts (text, images, videos), follow other users, see a personalized feed of posts from followed accounts, and interact (like, comment, share). Non-functional requirements: feed generation under 200ms, support 100 million new posts per day, and eventual consistency within 5 seconds.

Step 2: Design the fan-out strategy. For regular users (fewer than 10,000 followers), use fan-out-on-write: when they post, immediately push the post ID to all followers' feed caches in Redis Cluster. For celebrity users (above 10,000 followers), use fan-out-on-read: fetch their latest posts at feed-read time and merge with the pre-computed feed. Justify this hybrid approach with back-of-the-envelope calculations.

Step 3: Design the feed ranking algorithm. Retrieve the candidate posts from the feed cache (last 500 posts). Score each post using features: post age decay, affinity score (how often the user interacts with the author), content type preference, engagement velocity (likes and comments in the first hour), and diversity factor (avoid showing too many posts from one author). Use gradient-boosted decision tree for the scoring function.

Step 4: Architect the data storage layer. Use MySQL with sharding for the social graph (follow relationships) and post metadata. Use Redis Cluster for pre-computed feed lists (sorted sets of post IDs per user). Store post content (text, media URLs) in DynamoDB. Design the schema to support efficient queries for mutual friends, suggested follows, and trending topics.

Step 5: Implement real-time feed updates using WebSockets with Redis Pub/Sub. When a new post is created by a followed user, push a lightweight notification to active clients. The client should prepend the new post to the feed without a full reload. Handle offline users by marking their feed cache as stale for refresh on next open.

Step 6: Design the content moderation pipeline that screens every post before it enters the feed fan-out. Run automated checks for spam, hate speech, and policy violations using a classification model. Queue flagged content for human review. Implement an appeals workflow and audit trail for moderation decisions.

What this prompt does

This prompt positions the AI as a principal engineer designing a social media news feed for a platform with [user_count] users where [dau_percentage] are daily active. It covers six steps: requirements and consistency targets, the fan-out strategy, the ranking algorithm, the storage layer, real-time updates, and content moderation. The centerpiece is a hybrid fan-out: fan-out-on-write for users below [follower_threshold] followers and fan-out-on-read for celebrities above it, justified with back-of-the-envelope math.

The structure works because feed systems live or die on the write-versus-read fan-out tradeoff. Pushing every post to all followers' caches in [feed_cache] is fast to read but catastrophic when a celebrity with millions of followers posts — hence the threshold split at [follower_threshold]. The ranking step scores a candidate pool of [candidate_pool_size] posts using age decay, author affinity, content-type preference, engagement velocity, and a diversity factor via [ranking_model], so the feed is personalized rather than purely chronological. Meanwhile [realtime_technology] pushes lightweight notifications so active clients prepend new posts without a full reload, and offline users get their feed cache marked stale for refresh on next open.

When to use it

  • You're architecting a feed or activity stream and need the fan-out decision pinned down first
  • You want the write-versus-read tradeoff justified with rough capacity math
  • You need a ranking design beyond reverse-chronological order
  • You're choosing storage for the social graph, feed lists, and post content separately
  • You want real-time feed updates without forcing full reloads
  • You need content moderation designed into the fan-out path, not bolted on later
  • You're reasoning about consistency within a [consistency_window] rather than strict guarantees

Example output

Expect a design document: the requirements and consistency window, a fan-out section with back-of-the-envelope calculations defending the hybrid approach against the [follower_threshold] split, a ranking pipeline listing the scoring features, a storage breakdown mapping the social graph to [primary_database], feed lists to [feed_cache], and content to [content_store], a real-time update flow using [realtime_technology], and a moderation pipeline with automated classification, a human-review queue, an appeals workflow, and an audit trail. It reads as an architecture walkthrough, not code.

Pro tips

  • Set [follower_threshold] thoughtfully — it's the dial that balances write amplification against read-time merge cost
  • Keep [candidate_pool_size] bounded; ranking more posts improves quality but raises feed-generation latency
  • Use [feed_cache] for post-ID lists, not full post bodies; store content in [content_store] and hydrate at read time
  • Be realistic about [consistency_window] — strict consistency on a feed is expensive and rarely worth it
  • Put moderation before fan-out so flagged content never reaches caches; cleaning it up after is far harder
  • Force the fan-out math early; the numbers, not intuition, should decide your [follower_threshold]

Frequently Asked Questions

What's the difference between fan-out-on-write and fan-out-on-read here?
Fan-out-on-write pushes a new post into every follower's feed cache immediately, making reads fast but writes expensive. Fan-out-on-read fetches a user's latest posts at read time and merges them, which suits celebrities above `[follower_threshold]` whose huge follower counts would make write fan-out prohibitively costly.
Why use a hybrid approach instead of picking one fan-out model?
Pure write fan-out collapses when a high-follower account posts, while pure read fan-out makes every feed load slower. The hybrid uses write fan-out for ordinary users and read fan-out for accounts above `[follower_threshold]`, capturing the strengths of each and is why the prompt asks you to justify the split with math.
Does the feed have to be in chronological order?
No. The ranking step scores a pool of `[candidate_pool_size]` candidate posts using features like age decay, author affinity, engagement velocity, and a diversity factor via `[ranking_model]`. Chronological order is just one input, so the resulting feed is personalized rather than strictly time-ordered.
Where does content moderation fit in the pipeline?
Moderation runs before fan-out, screening every post for spam, hate speech, and policy violations with a classification model and queuing flagged content for human review. Placing it ahead of fan-out keeps violating posts out of follower caches entirely, which is far cleaner than retracting them afterward.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in System Design Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support