FSD Frontend System Design

Part VI — The Blueprint · Lesson 11.2

HLD – Photo Sharing App (Instagram)

In one lineAn image pipeline feeding an infinite feed — the two hard problems are upload and scroll.

Where you've seen itPosting a 4MB photo that appears almost immediately, then scrolling past a hundred images without a single frame drop.

  • Time20 min
  • DiagramUpload → transcode → CDN, plus the feed fetch path
  • Chapter11 · High Level Design

Diagram

Step 1⁠–⁠2Scope and scale
In scopefeed · post detail · upload · like/comment · profile
Out of scopestories · reels · DMs · search · ads
Scale500M DAU · ~30 posts/session · 4MB in → 200KB out · mobile web first · median device mid-tier Android
diagram
diagram

Lessons in this diagram6.9 API Caching6.5 Indexed DB

diagram
6b · DEEP DIVE — FEED SCROLL AT 60fps

  cursor pagination (10.11)  no duplicates when new posts arrive
  virtualization (10.7)      constant DOM size, flat memory
  <img srcset> + sizes       right variant per device pixel ratio
  fetchpriority=high on #1   the LCP image (5.5)
  loading=lazy below fold    never on the first card
  aspect-ratio boxes         reserve space → CLS ≈ 0 (5.1)
  IntersectionObserver       prefetch next page 400px early

How it works

  1. Feed = cursor-paginated, normalized store (6.6) so a like updates the post everywhere at once.
  2. Images dominate everything — variants, modern formats, and correct sizes matter more than any JS optimisation.
  3. Upload is direct-to-storage with client-side downscaling and an optimistic local preview.
  4. Interactions (like, follow) are optimistic with rollback (6.9).
  5. Rendering: SSR or SSG the shell for LCP, hydrate the feed, stream below-the-fold content (5.6).

Trade-offs

ChoiceCost
Client-side downscaleCPU on device, slight quality loss
Direct-to-storage uploadPresigned URL plumbing, harder validation
Optimistic postingRollback UI when transcoding fails
Virtualized feedComplexity, harder Ctrl-F and SEO

Interview angle

"The feed janks after a minute of scrolling. Why?"

  • Unbounded DOM: every scrolled card is still mounted, so memory and layout cost grow linearly — virtualize.
  • Images: wrong variant for the device, no aspect-ratio box, decoding on the main thread — use srcset, reserved space, and decoding="async".
  • Then verify with a flame chart (5.4) rather than guessing; long tasks name the culprit.

Recap

  • Two hard problems: upload latency and scroll performance.
  • Downscale on the client, upload direct to storage, preview optimistically.
  • Cursor pagination + virtualization + correct image variants carry the feed.