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.
Diagram
| Step 1–2 | Scope and scale |
|---|---|
| In scope | feed · post detail · upload · like/comment · profile |
| Out of scope | stories · reels · DMs · search · ads |
| Scale | 500M DAU · ~30 posts/session · 4MB in → 200KB out · mobile web first · median device mid-tier Android |
Lessons in this diagram6.9 API Caching6.5 Indexed DB
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 earlyHow it works
- Feed = cursor-paginated, normalized store (6.6) so a like updates the post everywhere at once.
- Images dominate everything — variants, modern formats, and correct
sizesmatter more than any JS optimisation. - Upload is direct-to-storage with client-side downscaling and an optimistic local preview.
- Interactions (like, follow) are optimistic with rollback (6.9).
- Rendering: SSR or SSG the shell for LCP, hydrate the feed, stream below-the-fold content (5.6).
Trade-offs
| Choice | Cost |
|---|---|
| Client-side downscale | CPU on device, slight quality loss |
| Direct-to-storage upload | Presigned URL plumbing, harder validation |
| Optimistic posting | Rollback UI when transcoding fails |
| Virtualized feed | Complexity, 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-ratiobox, decoding on the main thread — usesrcset, reserved space, anddecoding="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.