FSD Frontend System Design

Chapter 11 · High Level Design

Interview drill

14 questions from this chapter. Answer each one out loud first, then open it to compare.

  1. 11.1"Design Instagram's frontend."
    • Scope out loud first: feed and upload for mobile web, excluding stories, DMs, and reels — then confirm.
    • Give a number: 500M DAU, ~30 posts per session, images 200KB after transform.
    • Then follow the frame, and reserve the middle 15 minutes for the two deep dives, which is where the grading actually happens.

    Review 11.1 HLD Overview →

  2. 11.2"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.

    Review 11.2 HLD – Photo Sharing App (Instagram) →

  3. 11.3"Why not just SSR the whole site?"
    • Product and category pages are identical for everyone — rendering them per request wastes capacity that matters on sale days.
    • ISR at the edge gives the same SEO and a better LCP, with a client island keeping price and stock accurate.
    • Cart and checkout are per-user and must never be cached, so those stay client-rendered with no-store.

    Review 11.3 HLD – E-commerce App (Amazon, Flipkart) →

  4. 11.4"New posts arrive while the user is reading. What do you do?"
    • Buffer them and show a count pill; only insert automatically when scroll is at the very top.
    • Use cursor pagination so those inserts don't cause duplicates on the next page fetch.
    • Patch by id into a normalized store, so a like on one post doesn't re-render the entire list (10.5).

    Review 11.4 HLD – News Media Feed (Facebook, Twitter) →

  5. 11.5"The video keeps stalling on mobile. What do you change?"
    • Check the buffer policy first: the player should drop a rung on a draining buffer rather than defending quality.
    • Shorten segment length so adaptation reacts faster, and cap the maximum rung on small screens where 4K is invisible anyway.
    • Verify with rebuffer ratio in telemetry, not by watching it once on a good connection.

    Review 11.5 HLD – Video Streaming (Netflix) →

  6. 11.6"Music stops when the user navigates. Why, and how do you fix it?"
    • The <audio> element is inside a route, so navigation unmounts and recreates it.
    • Hoist a single player instance above the router and drive it from a global store; routes dispatch play/pause intents only.
    • Then add Media Session so hardware and lock-screen controls work, which is expected behaviour for anything audio.

    Review 11.6 HLD – Music Streaming (Spotify) →

  7. 11.7"Ten million concurrent viewers. WebSocket or SSE?"
    • SSE: the traffic is entirely one-way, and reconnect plus replay come free, which is the expensive part of a WebSocket build.
    • Terminate connections at edge PoPs fanning out from pub/sub, so the origin publishes once.
    • Then name the degradation ladder: full push → coalesced push → CDN-cached JSON polling, so peak load has a floor.

    Review 11.7 HLD – Live Commentary (CricInfo, Cricbuzz) →

  8. 11.8"The user archives 20 emails offline. What happens?"
    • Each action applies to IndexedDB immediately and appends to an ordered outbox; the UI reflects it at once.
    • On reconnect the outbox replays in order with idempotency keys, so retries can't double-apply.
    • Conflicts resolve by type — label changes merge, deletes win over edits, and conflicting drafts are kept as two versions rather than silently dropped.

    Review 11.8 HLD – Email Client →

  9. 11.9"Dragging gets slow with 5,000 shapes. What's wrong?"
    • You're probably redrawing the entire canvas per pointer event — split into static and active layers so a drag redraws one shape.
    • Hit testing is likely linear per mousemove; add a quadtree and cull to the viewport.
    • Coalesce pointer events into one requestAnimationFrame tick; browsers deliver far more of them than you can render.

    Review 11.9 HLD – Diagram Tools (Excalidraw) →

  10. 11.10"A widget needs to chart 40 million rows. How?"
    • It doesn't — the server aggregates to the granularity the chart can actually show, typically a few hundred points.
    • Downsample with an algorithm that preserves visual shape (LTTB) rather than naive sampling, which hides spikes.
    • Keep the widget independently loaded and cached by its query key so other cards render while it works.

    Review 11.10 HLD – Analytics Dashboard (Google Analytics) →

  11. 11.11"Two users type in the same sentence. How does it not break?"
    • Position indices shift under concurrent edits, so raw last-write-wins loses one of them.
    • OT transforms incoming operations against already-applied ones; CRDTs give every character a unique id so merges commute.
    • I'd pick based on constraints — OT with an authoritative server, CRDT if offline or peer-to-peer editing is required — and I'd apply locally first so typing never waits on the network.

    Review 11.11 HLD – Google Docs →

  12. 11.12"How do you recalculate a sheet with 10 million cells?"
    • You don't recalculate the sheet — you recalculate the dependents of the edited cell, found via reverse edges in a DAG and ordered topologically.
    • Detect cycles at parse time so a circular reference errors instead of hanging the tab.
    • If the dirty set is large, run recalculation in a Web Worker and batch one repaint per frame so typing stays responsive.

    Review 11.12 HLD – Google Sheets →

  13. 11.13"Would you use microfrontends here?"
    • Only above roughly four teams, or to strangle a legacy app route by route — otherwise a monorepo with clear module boundaries gives the same isolation with none of the runtime risk.
    • If yes: shell owns routing, auth, and shared singletons; remotes deploy independently; communication goes through the URL and events, never a shared store.
    • The recurring cost is shared-dependency version skew, and I'd plan an upgrade cadence for it upfront.

    Review 11.13 Microfrontend →

  14. 11.14"Two users drag the same card at once. What happens?"
    • Both apply optimistically and locally, so both feel instant; the server resolves position by last write and broadcasts the result.
    • Each client reconciles against its optimistic copy and animates to the server's answer, so no two boards disagree.
    • The card that lost shows a toast explaining the move — silently snapping back is what makes users distrust the tool.

    Review 11.14 HLD Kanban Board →