Practice Hub /
Media & FeedsMedium~35 min interview roundMetaXLinkedIn

Infinite Scroll Social Feed (Instagram / X)

Design a 60fps mobile-friendly social timeline with cursor pagination, DOM virtualization, optimistic likes, and clean media unloading.

1. Interactive System Architecture Diagram

Click any architecture component below to inspect its exact responsibilities and trace connected data flows.

Dispatch / Select Lookup / Optimistic Cursor Fetch Lazy Media Client UI Virtualized List State Store Normalized Entities Cache Layer Stale-While-Revalidate API Gateway Cursor Pagination CDN / Media Responsive Images
Selected ComponentClient UI — Virtualized List
  • Renders only visible viewport posts (windowing buffer ~5 items above/below).
  • Attaches IntersectionObserver sentinel 300px above list bottom to prefetch next page.
  • Uses aspect-ratio CSS boxes on media cards to guarantee zero layout shift (CLS = 0).

2. Interactive Trade-Off Simulator

Toggle between real architectural options to compare Pros, Cons, and exactly when to pick each choice in interviews.

Pagination Strategy

Which pagination strategy handles a live feed receiving new posts cleanly?

Pros

  • Zero duplicate or skipped posts when new items insert at top of timeline.
  • O(1) indexed DB seeks using opaque `(createdAt, id)` cursor.

Cons & Pitfalls

  • Cannot jump directly to "Page 7" arbitrarily.
Interview Rule of Thumb: Pick Cursor Pagination for every live infinite feed (X, Instagram, LinkedIn).
List DOM Rendering

How should 1,000+ scrolled posts be managed in browser DOM?

Pros

  • Keeps DOM node count constant (~20 cards) regardless of how far user scrolls.
  • Eliminates janky layouts and browser tab OOM crashes on mobile.

Cons & Pitfalls

  • Requires measured or estimated item heights for variable-height cards.
Interview Rule of Thumb: Pick Virtualization whenever feeds scroll unbounded (social, logs, chat).

3. RADIO Framework Breakdown & Interview Checklist

Review each RADIO pillar cleanly and check off sections as you master them.

0 / 5 Sections Reviewed
R

Requirements & Scope

  • Functional: Text/image/video feed, infinite scroll, optimistic like/bookmark, pull-to-refresh.
  • Non-Functional: Initial feed painted < 1.5s, 60fps scroll, zero CLS, mobile-first memory cap.
A

Architecture Components

  • Normalized Store (`postsById`, `usersById`) separated from view-specific `feedOrder[]`.
  • IntersectionObserver trigger decouples scroll detection from manual `onscroll` throttling.
  • Virtual Scroller / Dynamic Height Cache keeps off-screen posts out of active DOM.
D

Client Data Model

  • `FeedState: { ids: string[], nextCursor: string | null, status: "idle"|"loading" }`
  • `PostEntity: { id, authorId, text, mediaUrl, aspectRatio, likeCount, likedByMe }`
  • Dedup `Set<string>` guarantees identical IDs never render twice on screen.
I

Interface & API Contracts

  • `GET /api/v1/feed?cursor=eyJ0cyI6MTcwMH0&limit=15` -> `{ items, nextCursor, hasMore }`
  • `POST /api/v1/posts/:id/like` -> `{ likeCount, likedByMe }` (reconciles optimistic UI).
O

Performance & Optimizations

  • Auto-pause offscreen `<video>` elements via IntersectionObserver to save CPU/battery.
  • Reserve media space with `aspect-ratio` + `loading="lazy"` + responsive `srcset`.
  • Prefetch `N+1` cursor silently at 70% viewport depth so user never waits for spinner.