Frontend system design: build a Facebook social media feed
Covered in depth at [[frontend-system-design-design-a-news-feed-facebook]]. The headline architecture: cursor-paginated server-ranked feed, virtualized list, memoized post components, optimistic likes/comments with idempotency keys, lazy + responsive media, real-time updates via WebSocket or polling, SSR/SSG for first paint and SEO, service worker shell for offline-friendly repeat loads.
This is the same problem as [[frontend-system-design-design-a-news-feed-facebook]] — the principles are identical. Here's a compact recap with one extra deep-dive on Facebook-specific features (reactions, share modal, comments tree).
The architecture (recap)
- Cursor pagination — offset breaks under inserts.
- Infinite scroll via IntersectionObserver sentinel.
- Virtualization for long feeds.
- Memoized post components so liking one doesn't re-render thousands.
- Optimistic likes/reactions/comments with idempotency keys.
- Lazy media with reserved aspect ratios.
- Real-time updates via WebSocket for new likes/comments; "Show N new posts" pill for new posts.
- SSR/SSG for the home page; client-side for subsequent navigation.
- Service worker for shell + offline.
- Per-feed cache keys in React Query so back-nav restores instantly.
Facebook-specific surfaces
Reactions (not just Like)
- Long-press / hover surfaces the reaction picker (👍 ❤️ 😆 😮 😢 😡).
- Each post stores per-reaction counts.
- Optimistic: bump the new reaction, decrement the old one if changing.
Comments tree
- Top-level + replies (one level deep typically).
- Expand "View N more comments" inline.
- Comments themselves are optimistic.
- Long threads — paginate within the post.
Share modal
- Share to: feed, story, message, copy link.
- Each option has its own flow; the modal coordinates.
Live posts
- Live video posts have a different player (HLS + live indicator + reactions floating up).
- Treat as a streaming media variant (see [[frontend-system-design-design-video-streaming-netflix]]).
Privacy controls
- Visibility (public, friends, custom) shown per post.
- "See first" friends ranked higher.
- Audience selectors when posting.
Notifications panel
- Separate surface; pulls from the same event firehose as the feed.
Performance focus
- LCP = first visible post's image (or hero).
- Memoize posts.
- Code-split: stories, marketplace, watch tabs separate from main feed.
- Pre-fetch profile pages on hover.
Accessibility
- Post as
<article>with author + date in the accessible name. - Alt text on images (Facebook auto-generates if missing; user can override).
- Reaction picker is a menu with arrow-key navigation.
- Comments form keyboard-friendly.
Interview framing
"Same playbook as a generic news feed: cursor-pagination, virtualization, memoized posts, optimistic interactions with idempotency, lazy media. What's Facebook-specific is the reactions (multi-emoji, optimistic bump+decrement on change), the comments tree (top-level + one level of replies, inline-expanding pagination), the share modal coordinating multiple destinations, and live video as a streaming variant. Performance focus is the same — LCP on hero, memoize posts, code-split feature tabs. The reusable patterns dominate; the Facebook-specific stuff layers on top."
Follow-up questions
- •How does the reactions UX differ from a binary like?
- •How do you paginate comments within a post?
- •What's the interplay between feed and notifications data?
- •How would you handle a live video post?
Common mistakes
- •Treating reactions as a single counter — loses the per-reaction breakdown.
- •Comments fully loaded with each post — bandwidth blow-up.
- •Auto-shifting feed on new posts (use a pill).
- •Same player code for live and on-demand video.
Performance considerations
- •Same as any feed — virtualize, memoize, lazy media. Comments paginated within posts.
Edge cases
- •Reaction changed mid-flight (user spam-tapping).
- •Comments thread with thousands of replies.
- •Privacy boundary changes mid-session.
Real-world examples
- •Facebook News Feed, Twitter/X timeline, LinkedIn feed.