Design the web client of a video streaming service like Netflix.
Users sign in, pick a profile, and land on a browse page made of many horizontal rows ("Continue watching", "Trending now", genres). Hovering or focusing a title shows a preview. Selecting a title opens a details view, and "Play" starts a full-screen video player.
Requirements from the interviewer:
Cover the browse experience, the player architecture, data/API design, and performance, accessibility and reliability concerns.
A streaming client has two very different halves: a browse UI (a giant, image-heavy, keyboard-navigable grid of rows) and a player (a real-time media pipeline where the metric that matters is rebuffering, not React render time). A good answer designs both and explains how they hand off.
| Concern | Target |
|---|---|
| Time to first frame | < 2 s p75 after pressing Play on broadband; < 4 s on mobile |
| Rebuffering | < 0.5% of watch time spent stalled; zero stalls for most sessions |
| Quality | highest sustainable bitrate; minimal quality switches |
| Browse page | LCP < 2.5 s; 60 fps row scrolling; on TVs, focus moves < 100 ms after a key press |
| Memory | low-end TVs with ~1 GB RAM and slow CPUs: bounded DOM and image memory |
| Protection | DRM via EME (Widevine, PlayReady, FairPlay) and per-region licensing |
| Resume accuracy | within ~10 s of the last position across devices |
Encoding pipeline, CDN placement (e.g. Open Connect appliances), recommendation algorithms, payments, native apps.
The <video> element alone can play an MP4, but adaptive streaming needs a player engine built on Media Source
Extensions (MSE): it downloads a manifest (DASH .mpd or HLS .m3u8), picks a bitrate rendition, fetches media
segments, appends them to SourceBuffers, and handles DRM via Encrypted Media Extensions (EME). Use a proven engine
(Shaka Player, hls.js, dash.js, or an in-house one at Netflix scale) rather than writing one in an interview — but
explain how it works. Safari on iOS historically lacked MSE on iPhone (Managed Media Source arrived in iOS 17.1), so
native HLS playback remains a needed path.
<App>
<ProfileGate />
<BrowsePage>
<Billboard /> // hero with muted trailer
<RowList> // vertical virtualization
<Row title="Continue watching">
<RowTrack> // horizontal virtualization, arrows/paging
<TitleCard /> // boxart image; expands on hover/focus
<TitlePreviewPopover /> // shared preview player instance
<TitleDetailsModal />
<PlayerPage>
<VideoSurface /> // <video> element managed by the engine
<PlayerControls /> // play, seek bar, volume, tracks, fullscreen
<SubtitleRenderer /> // custom-rendered cues for styling consistency
<SkipIntroButton /> <NextEpisodeCard />
<PlayerErrorOverlay />
type ID = string;
interface Title {
id: ID;
type: 'movie' | 'show';
name: string;
synopsis: string;
maturityRating: string;
artwork: { boxart: ImageSet; billboard?: ImageSet; logo?: ImageSet }; // personalised artwork variants chosen by server
previewVideoId?: ID;
seasons?: { id: ID; number: number; episodeIds: ID[] }[];
}
interface ImageSet { url: string; width: number; height: number; variants: { w: number; url: string }[] }
interface Row {
id: ID;
title: string;
kind: 'continue_watching' | 'top10' | 'genre' | 'my_list' | 'standard';
titleIds: ID[]; // first page only; rest paginated
nextCursor?: string;
}
interface Bookmark { titleId: ID; episodeId?: ID; positionSec: number; durationSec: number; updatedAt: string }
// Player session state (client only, not in a global server cache)
interface PlaybackSession {
sessionId: ID;
titleId: ID;
state: 'loading' | 'playing' | 'paused' | 'buffering' | 'seeking' | 'ended' | 'error';
positionSec: number;
bufferedAheadSec: number;
currentBitrateKbps: number;
estimatedBandwidthKbps: number;
audioTrack: string; // language code
textTrack: string | null;
volume: number;
muted: boolean;
error?: { code: string; fatal: boolean };
}
interface BrowseStore {
titles: Record<ID, Title>; // normalized: a title appears in many rows
rows: Record<ID, Row>;
rowOrder: ID[];
bookmarks: Record<ID, Bookmark>;
focus: { rowIndex: number; perRowIndex: Record<ID, number> }; // remembered focus for TV navigation
}
Where state lives: catalog data in a normalized query cache; bookmarks fetched with the page and updated by the
player; high-frequency player state (position, buffer) lives in the engine and refs, surfaced to React at a low
rate (e.g. 4 Hz for the seek bar via timeupdate, not 60 Hz), so the player UI doesn't re-render constantly.
User preferences (subtitle language, size, audio language) persist per profile on the server, cached locally.
GET /api/browse?profileId=p_2&rows=0-8&itemsPerRow=20
{
"rows": [
{ "id": "r_cw", "kind": "continue_watching", "title": "Continue Watching for Sam", "titleIds": ["t_12", "t_88"], "nextCursor": null },
{ "id": "r_trend", "kind": "standard", "title": "Trending Now", "titleIds": ["t_5", "t_9"], "nextCursor": "c2"}
],
"titles": {
"t_12": { "id": "t_12", "type": "show", "name": "The Long Orbit",
"artwork": { "boxart": { "url": "https://art.example.com/t_12/b_342.webp", "width": 342, "height": 192, "variants": [] } } }
},
"bookmarks": { "t_12": { "titleId": "t_12", "episodeId": "e_4", "positionSec": 1312, "durationSec": 2950, "updatedAt": "2025-03-01T21:12:00Z" } },
"nextRowsCursor": "rows:9"
}
Two-level pagination: rows load lazily as the user scrolls down (rows cursor), and each row loads more titles when
the user pages right (/api/rows/r_trend?cursor=c2). Cursor pagination because rows are personalised and generated
per session. GraphQL fits this nested, per-device shape well (Netflix has written about Falcor and later GraphQL
federation); REST with side-loaded entities works too.
POST /api/playback
{ "titleId": "t_12", "episodeId": "e_4", "profileId": "p_2",
"capabilities": { "codecs": ["av01", "hvc1", "avc1"], "drm": ["com.widevine.alpha"], "hdr": false, "maxHeight": 1080 } }
{
"sessionId": "ps_771",
"manifestUrl": "https://cdn3.example.net/m/e_4/manifest.mpd?token=...",
"fallbackManifestUrls": ["https://cdn7.example.net/m/e_4/manifest.mpd?token=..."],
"license": { "keySystem": "com.widevine.alpha", "url": "https://license.example.com/widevine?session=ps_771" },
"startPositionSec": 1312,
"markers": { "introStart": 30, "introEnd": 92, "creditsStart": 2870 },
"textTracks": [{ "lang": "en", "kind": "subtitles", "url": "https://cdn3.example.net/s/e_4/en.vtt" }],
"nextEpisodeId": "e_5"
}
The client detects capabilities with MediaSource.isTypeSupported, navigator.mediaCapabilities.decodingInfo
(includes smoothness and power efficiency) and navigator.requestMediaKeySystemAccess, so the server returns only
renditions the device can play.
POST /api/playback/ps_771/events
{ "events": [
{ "type": "heartbeat", "positionSec": 1342, "bitrateKbps": 5800, "bufferSec": 24, "ts": 1740863521000 },
{ "type": "rebuffer", "positionSec": 1350, "durationMs": 820 },
{ "type": "pause", "positionSec": 1361 }
] }
Heartbeats every ~30 s plus on pause/seek/exit update the bookmark. On tab close, send the final position with
navigator.sendBeacon on visibilitychange → hidden.
interface PlayerProps {
titleId: ID;
episodeId?: ID;
startPositionSec?: number;
autoPlay?: boolean;
onExit: () => void;
onEnded?: (nextEpisodeId?: ID) => void;
}
interface RowProps {
rowId: ID;
isFocusedRow: boolean; // TV focus engine
onCardFocus: (titleId: ID, index: number) => void;
renderCard: (titleId: ID, opts: { focused: boolean; priority: boolean }) => React.ReactNode;
}
SourceBuffer memory is limited and QuotaExceededError must be handled by evicting played ranges).mediaCapabilities).keystatuseschange (e.g. output restricted for HDCP) by
falling back to lower resolutions instead of failing.srcset sized for the card width; WebP/AVIF; fixed aspect-ratio boxes; the first
visible row eager, the rest lazy. Personalised artwork is chosen server-side, so the client just renders URLs.<video> per card. A single preview player instance moves to the
hovered/focused card, plays a short low-bitrate muted preview after a dwell delay, and is torn down when focus
leaves. Respect a user setting to disable autoplay previews and prefers-reduced-motion.transform/opacity only; avoid layout-triggering properties on low-end TV
CPUs. The View Transitions API can animate card → details where supported.tabindex="-1" + roving focus rather than tabbing through
hundreds of cards.transform (cheaper than scrollLeft on some TV
engines).role="slider" with aria-valuetext="22 minutes 5 seconds of 49 minutes".lang attribute on cue
containers.Intl (Intl.DurationFormat where supported, with fallback).HttpOnly cookies, CSRF protection; subtitle files are parsed as text, never injected
as HTML (cue text may contain markup tags — whitelist <i>, <b> only).Why not just use a <video src="movie.mp4">? No adaptation to bandwidth, poor seeking for long files, no DRM
key rotation, and wasteful bytes. MSE + segmented ABR solves all of these.
HLS or DASH? DASH is codec-agnostic and common with MSE players; HLS is required for native playback on older iOS. With CMAF segments, one set of media files can serve both manifests.
How does "Continue watching" stay accurate? Heartbeats every ~30 s, plus events on pause/seek/exit and a beacon on
page hide; the server stores the latest by updatedAt, so the most recent device wins.
How would you support live sports? Shorter segments or low-latency modes (LL-HLS, LL-DASH with chunked CMAF), a live edge indicator, smaller buffers, and a DVR window; latency vs rebuffer trade-off becomes explicit.
How do previews avoid wasting bandwidth? Dwell delay before playing, low bitrate renditions, cancel on focus change, disabled on Save-Data or metered connections.
Spotted a mistake or a rights concern? Report an issue