Build it. The database schema, API, code and platform limits for a video streaming app are on a separate page: Build it: a video streaming app on Android and iOS (21 min read).
How to read this. This page follows a 45 minute round. The build guide has the schema, API, code and platform tables. The follow-up questions are my reconstruction of challenges that public prep material reports: offline use and rollout. They are not real transcripts.
TL;DR. My answer: let the player (the code that plays video) pick the bitrate (bits per second). Spend your time on three things the player cannot do. Own the player outside any screen. Spend data on purpose. Make downloads and licenses survive when the app is killed (stopped by the system).
Patterns in this round.
- State machine (playback state is one of the things the case covers)
- Scoped owner (the player is owned outside any screen, by a service, because the case rejects a plain singleton)
More in design patterns in mobile rounds.
Free: one follow-up round a week. A short interview question with a weak and a strong answer, by email. You also get the cheat sheet.
1. Scope and constraints (minutes 0 to 4)
In short: In scope: long videos on demand, downloads and resume. Live and a short-video feed wait.
A prompt I expect: "Design a video app for phones. People browse, watch, download for a flight, and resume." I ask five questions:
- Short videos, long videos, or both? Long videos first. The autoplay feed (videos start by themselves) is parked (left for later).
- Live or on demand? On demand.
- Offline downloads, and does the content need a license (permission to play protected video)? Yes.
- Resume on other devices? Yes, same account.
- Background audio and picture-in-picture (a small floating video window)? Yes, on the watch screen.
| In scope | Out of scope | Parked until you ask |
|---|---|---|
| Browse list, watch screen | Upload, transcoding (converting video to many sizes) | Live streaming |
| Adaptive playback, resume | Recommendations, search | A short-video feed |
| Downloads with a license | Ads | Subtitle memory |
| Background audio, picture-in-picture | Several CDNs (content delivery networks: servers near users) |
Four things the phone does to this design:
| What the phone does | Requirement at risk | Deep dive |
|---|---|---|
| Turns the screen, moves the app to the background, or kills the app | Playback and position survive | Client structure (3) |
| Weak signal, or a switch from Wi-Fi to cellular | No long stalls (the video stops to wait for data), no stall loop | Fast start (4.1) |
| Data plan and battery | Data spent on purpose, no wasted preload (loading part of a video early) | Fast start (4.1) |
| Limits or cancels downloads that run in the background | Downloads resume; licenses stay valid | Downloads (4.2) |
Your decision. The scope follow-up question I expect: "Add a short-video feed and live." Do you say yes, or keep both parked?
First idea, and why it fails. Say yes to both. Then time runs out before offline use and resume appear. The phone makes those two parts hard.
What I would say. I keep long videos on demand. Live changes the segment length (a segment is a short piece of video) and removes offline use. A feed changes the preload depth (how much of the next videos I load).
Say this. "Long videos, on demand, with downloads and resume. Live and a short-video feed each change preload and packaging, so I am parking them. I will build the player so a feed can plug in later. Tell me if you want one earlier."
The follow-up question I expect: "Can the same player serve a feed later?"
Yes, if no screen owns the player and preload is a policy that I can replace.
2. Data and contracts (minutes 4 to 14)
In short: The feed carries only small metadata. A separate playback call carries the address, license details and resume position.
Your decision. Where does the playable address live? In every feed row so play is one tap, in a call made just before play, or in a call made for the whole page?
First idea, and why it fails. Put the manifest address (the file that lists a video's segments) in each feed row, so play is one tap. But signed addresses (addresses with a time limit) expire, so a row loaded ten minutes ago can fail on tap. A page of ten rows also needs ten extra lookups.
What I would say. The feed returns only small metadata (thumbnail, title, channel, length). A playback call returns the manifest address, license details and resume position. I make it when a video is about to play or preload. I reject one call for a whole page.
The follow-up question I expect: "The address expires in the middle of a session."
I call playback again and set up the player again at the current position. The viewer sees a short pause.
The follow-up question I expect: "Why not send the device time with each progress update?"
Device clocks are not exact. The server adds its own time (a stamp) to every update, and the newest stamp wins.
- Progress is an absolute position, so a retry (sending the request again) is safe. This is idempotent: doing it twice has the same result as doing it once.
- On one device, a saved row not yet uploaded wins until it uploads. These waiting rows form the progress queue.
The follow-up after that: "The app is killed while the video plays. Where does the user resume?"
- I save the position to the local database on pause and every few seconds while playing.
- I do not rely on a stop callback alone. A crash or a kill may skip it.
- The saved row joins the progress queue and uploads later. The local row wins until it does.
The schema, the REST block and the size arithmetic are in the build guide.
3. Client structure (minutes 14 to 22)
In short: One long-lived service owns the player. Screens connect to it and send commands.
Your decision. Who owns the player: the watch screen, its ViewModel, or a service that lives as long as playback?
First idea, and why it fails. The screen or its ViewModel (the object that holds a screen's state). An activity that owns the player restarts it when the screen rotates. A ViewModel survives rotation, but the system clears it when its screen leaves the back stack (ViewModel). Nothing in it keeps audio playing in the background.
What I would say. A media service (a part of the app that runs without a screen) holds the player and a media session (the object that shows controls to the system). Screens attach a controller. I reject the activity, the ViewModel, and a plain singleton with no service. Media3 (the Android media library) describes this design in its background playback guide.
The follow-up question I expect: "On iOS there is no service. What keeps playback alive?"
An app-level object holds the player. The audio session category (a setting for media apps) and the audio background mode (a permission to run in the background) keep it playing.
The follow-up question I expect: "The feed preview and the watch screen both want the player."
One player moves between screens. I never create a second one when the network changes.
More links
- UI to Video repository: metadata
- Video repository to REST API
- Playback service to Analytics: metrics
- Playback service to License server: license
- Preload manager to Segment cache: fills
- CDN to Preload manager: segments
The architecture guide has no player layer, so the service sits beside the UI and data layers. Three rules:
- The screen never touches a data source.
- Metadata and video bytes travel on separate paths.
- The service releases the player only when the service stops.
4. Make the hard part work (minutes 22 to 40)
In short: Start fast without wasting data, and make downloads and licenses survive a kill.
4.1 Fast start without wasting data (minutes 22 to 31)
Your decision. The user taps play, or the next episode is about to start. Do you preload the whole next video, write your own bitrate logic, or set limits and let the player adapt?
First idea, and why it fails. Preload the whole next video at a high rung (one quality level in the list of levels, the ladder), or write a bitrate algorithm. On a metered link (one that costs the user data or money), the bytes are wasted when the user skips. Preload also takes bandwidth from the visible video, and each preloaded video holds memory.
What I would say. I ask packaging for a low default rung, 6 second segments and a very low cellular rung. I cap quality by network (a maximum for each network type). I preload a few seconds of the next video, on unmetered links only. I reject full-file preload and my own algorithm.
Say this. "I let the player pick the bitrate, and I control its limits. I ask packaging for a low first rung and short segments. I cap quality on cellular. I preload three seconds of the next episode, only on an unmetered link. On iOS I set the same caps with preferredPeakBitRate and its expensive-network variant. I measure time to first frame (the wait from tap to first picture) and the stall share (the share of watch time spent stalled)."
The follow-up question I expect: "Why not write your own bitrate algorithm?"
Not before I have data about groups of users, split by network and device. The player's selection is tuned and tested. I control the ladder and the caps.
The follow-up question I expect: "The user moves from Wi-Fi to cellular, or turns on data saver."
Preload stops, the cap drops, and feed autoplay stops. The app turns both system signals into one flag (an on-off setting).
- Android: check for a metered link first, then the Data Saver state (Data Saver).
- iOS: the expensive path (such as cellular) and the constrained path (Low Data Mode) are separate signals (isConstrained).
4.2 Downloads that survive (minutes 31 to 40)
Your decision. Someone downloads a film for a flight. Who runs the download, where do the bytes go, and when does the license arrive?
First idea, and why it fails. One background job downloads the file, and the license arrives on play. But the system can kill the app mid-download. On Android 15 and later, a data-sync service has a time limit of 6 hours in 24 (timeouts). On iOS, a force-quit (the user swipes the app away) cancels active downloads. On the plane there is no network for the license.
What I would say. I use the platform's download engine, started from a tap. I save a license with its expiry next to the file, and I renew it while online. Downloads live in a separate cache that never evicts (on iOS, the system can still remove them, see 4.3). I reject the streaming cache, because it evicts. I also reject my own downloader, because I would rebuild track selection.
Say this. "A download starts from a tap. The engine saves the file, and I save a license with an expiry. If the system kills the app, the download is paused, not failed. It resumes when the system or the user restarts it. Offline, I show the expiry date, and a clear message when it passes."
The follow-up question I expect: "The 6 hour limit hits in the middle of a big download."
The service gets a few seconds to stop. I stop it in the timeout callback (called by the system at the limit) and mark the download paused.
- Media3 documents a scheduler that restarts downloads when its requirements are met, such as network type (downloading media). My reading is that it also restarts them after this timeout.
The follow-up question I expect: "The license expired and there is no network."
Playback stays blocked with a clear message and no retry loop. The license renews when the phone is online.
- DRM has two systems. Widevine runs on Android. FairPlay runs on iOS, through
AVContentKeySession. - Widevine has security levels. Level 1 uses hardware. Level 3 uses software, and servers often limit it to lower resolutions. The license server decides.
- An offline license often has two timers: how long you may keep it, and how long you may play after the first play. Show both to the user if your license server uses both.
- FairPlay needs your app certificate and a key exchange with your license server. It generally needs a real device, not the simulator.
The follow-up question I expect: "The app restarts, and the user taps Download again."
I give each download a stable ID made from the video and the account. A second tap finds the same row and resumes it, so there is no new copy. If the license or playback call gets a 401, I refresh the login once and retry. If that fails, I show "Sign in to keep watching" and keep the file.
4.3 Where iOS changes the design
- iOS has no background service. The audio session and the background mode keep audio playing. A force-quit cancels downloads, so the list needs an "interrupted" state.
- Background audio for video:
AVPlayerViewControllerhandles it. If you draw with a bareAVPlayerLayer, detach the player from the layer when the app goes to the background. Then audio keeps playing. - Lock screen controls come from
MPNowPlayingInfoCenterandMPRemoteCommandCenter. They are the iOS match for the media session. - Downloads on iOS are not a cache you control. The system can remove saved HLS (HTTP Live Streaming, Apple's streaming format) assets when storage is low. Use
AVAssetDownloadStorageManagerto set a priority and an expiry. Treat a missing file as a normal case. - Only on-demand streams can be saved. A live title has no download button (Apple).
5. Break it, ship it, roll it back (minutes 40 to 45)
In short: Each failure ends in a resumed download, a clear message, or a correct position, never a silent loss.
| Failure | User sees | Data holds | Recovery |
|---|---|---|---|
| Background kill or limit | "Paused" on the download | Partial file, download index | Stop in the timeout callback; resume later |
| Second tap on Download after a restart | The same download, resumed | One row for each video and account | Find the row by its stable ID and resume it. Never start a new copy |
| Login expires during a download or license renewal (401) | "Sign in to keep watching" if refresh fails | The file and the license expiry | Refresh the login once and retry. If it fails, keep the file |
| Interrupted large download | "Download interrupted" and a resume button | Partial file, saved location | Resume on the next launch |
| Disk full during a download | "Not enough space", download paused | Partial file and download index | Check free space before starting. On a write error, pause with the reason and no retry loop. Resume when the user frees space |
| Device clock changed while offline | The date shown may be wrong | License and expiry from the server | I treat the device clock as a hint only. The license rules decide, and the app renews the license when online |
| Long time offline | "Go online to renew" | File and license expiry | Renew when online; no loop of retries |
| The credential (the signed address) expires during use | A short pause, then playback | Current position | Make the playback call again; set up the player again there |
| Updates arrive in the wrong order | The right position on the next device | Server time, absolute position | The server keeps the newest stamp |
| Low storage, or old data removed | Streaming restarts a segment; downloads stay | Two separate caches | Streaming cache evicts; download cache does not |
| An old app version meets a new server contract (agreed data format) | Old apps keep playing | Quality ladder and DRM type for each app capability | The server answers by what the app supports |
Rows without a source link are my design choices. Sources are in Further reading.
At release:
- A Google Play staged rollout (a release to a growing share of users) can be halted. Users who have the build keep it (Play Console).
- An App Store phased release (a release in steps) can be paused for up to 30 days (Apple). The page does not mention reverting installed copies.
- Old versions stay installed for months. So the playback call keeps returning an H.264 ladder (a video format older devices decode) and the older DRM type.
- A remote flag (a setting the server controls) keeps the old player in the app. It is the only rollback (a return to the old behavior) that reaches installed apps. A crash at launch still needs a new build.
- The download index and license format cannot be flagged off, so they ship one release ahead. Media3 changed its service class in version 1.10 (release notes).
Say this. "I cannot recall a bad build, so the rollback is the flag plus a fixed build. I would watch time to first frame, stall share, playback failures and download failures. I leave out upload, recommendations and ads."
6. Follow-ups that change a constraint
In short: Each follow-up changes one constraint. A strong answer says what breaks.
- The link drops to a few hundred kbit/s for ten minutes, and the user moves to the 80 percent point (an example). Strong: the player drops to the lowest rung, and I cancel the old preload. Seek previews need I-frame playlists (key frames only) from packaging. Weak: "Buffer more."
- Add a short vertical video feed (parked). Strong: a small preload depth and a pool of players. Also a cap on active decoders (parts that turn video data into pictures). Weak: "Autoplay everything."
- The user also has a tablet, and wants subtitles remembered (parked). Strong: the server sets the order of position updates. The subtitle choice belongs to the user, not to a device or video. Downloads stay per device. Weak: "Use the last device time."
- The user signs out, or switches account, with downloads on the phone. Strong: delete the old account's files and licenses, and clear the progress queue. Weak: "Leave the files and fix it later."
- Stalls double for one carrier (a phone network company) after a release (parked: several CDNs). Strong: split the quality data by carrier, device and CDN. The playback call returns more than one host (server address), and the client switches after repeated failures. Weak: "Restart the player on every error."
- Add live streaming (parked) while old versions are still in use. Strong: live needs short segments, no long preload and no offline use. The server offers live only to apps that support it. Weak: "Change the manifest for everyone."
7. What changes by level
In short: As I read it, levels differ in who raises the problem: the interviewer, the candidate, or the candidate with a plan.
These levels are my own reading. They are not any company's scoring guide.
| Level | The answer covers | I want to hear |
|---|---|---|
| Mid-level | HLS (HTTP Live Streaming, Apple's streaming format) in the platform player, a player holder that survives screen changes, a saved position, error handling | "The player picks the bitrate, and I set the limits." |
| Senior | A service-owned player, limited preload that respects data saver, a separate download cache, license expiry, server-ordered progress, and the two quality numbers (time to first frame, stall share) | "Preload has a cost and may be wasted, so I keep it small and switch it off on metered links." |
| Staff | A shared playback module, a rollout plan for a player change, tuning by group of users, a cost model, and DRM policy with the backend (staff guide) | "Here is how I would know the new player is better before I turn off the old one." |
Common weak answers. Ten minutes on transcoding. "Just use ExoPlayer (the Android player in Media3)," with nothing about the player's lifetime. Screens that own the player. No plan for cellular. No license expiry. No rollout plan. A custom bitrate algorithm first. They are not data from a study.
Staff answer: the decision and the rollout
- Decision: one shared playback module (shared code for the player, cache, DRM and quality reporting) for every app.
- Alternative: each app owns its player. It starts faster, but the apps drift apart.
- Revisit trigger: split the module if one app needs behavior that it cannot give without a fork (a private copy of the code). Also split it if its release schedule blocks a team for a cycle.
- Rollout: the new player ships behind the flag from section 5, then in a staged release. I compare time to first frame and stall share on matched cohorts (same network and device class).
- Guardrail: crash-free sessions and the playback failure rate must not get worse than with the old player.
- Rollback: the old player stays behind the flag. Downloads and licenses tie users to the player that made them, so the flag first needs a plan to move them.
What I read and what is my view: I read the Media3, Android timeout, Apple download and HLS facts in official documents. The module split, metrics, guardrails and level text are my opinion. The native vs cross-platform guide covers shared code versus modules.
Test yourself
In short: Seven questions from this case. Answer each one out loud first, then open the answer.
1. Where does the playable address live, and why not in every feed row?
In a playback call made just before play or preload. Signed addresses expire, so a row loaded ten minutes ago can fail on tap, and a page of ten rows would need ten lookups anyway. The feed carries only small metadata.
2. Who owns the player, and why not the watch screen or its ViewModel?
A media service holds the player and a media session, and screens attach a controller. An activity restarts the player on rotation. A ViewModel is cleared when its screen leaves the back stack, and nothing in it keeps audio playing in the background.
3. Do you preload the next video, and how much?
A few seconds, about three, and only on an unmetered link. Full-file preload wastes bytes on a metered link when the user skips, and it takes bandwidth from the visible video.
4. Why not write your own bitrate algorithm?
Not before there is data about groups of users, split by network and device. The player's selection is tuned and tested. The app controls the ladder and the caps, such as a low first rung and a cellular cap.
5. Someone downloads a film for a flight. How do the file and the license survive?
The platform's download engine saves the file, and a license with its expiry is saved next to it and renewed while online. Downloads live in a separate cache that never evicts. A killed app means a paused download, not a failed one.
6. The playback address expires in the middle of a session. What happens?
The app calls playback again and sets up the player again at the current position. The viewer sees a short pause.
7. A user leaves a video app playing audio on iOS. What keeps the sound going?
iOS has no background service. The audio session and the background mode keep audio playing. AVPlayerViewController handles it. With a bare AVPlayerLayer, detach the player from the layer when the app goes to the background.
Further reading (official docs)
- Build it: a video streaming app on Android and iOS: schema, REST, code, packaging asks and platform limits for this case
- Media3: background playback with MediaSessionService
- Media3 ExoPlayer: downloading media
- Media3 ExoPlayer: DRM
- Foreground service timeouts (Android)
- Data Saver (Android)
- Media3 release notes
- HTTP Live Streaming (Apple)
- AVAssetDownloadURLSession (Apple)
- Playing and persisting HTTP Live Streams (Apple)
I compared this page against these references to find gaps. I took ideas from them, not structure or wording:
- The ByteByteGo mobile system design book and the DesignGurus mobile course
- The Educative mobile course and the weeBox mobile system design repository
- The Hello Interview YouTube breakdown and the techinterview.org video articles
- The Android Developers Blog posts on Media3 preloading
Words on this page (13)
- CDN
- Content delivery network. Servers close to users that keep copies of your files.
- Cohort
- A group of users who share a trait, such as the same network or the same type of phone.
- Crash-free rate
- The share of sessions that end without a crash.
- Decode
- To turn compressed video or image data into pictures that the screen can draw. It takes time, memory and battery.
- DRM
- Digital rights management. Locks that stop people from copying licensed video.
- HLS
- HTTP Live Streaming. A video format from Apple that splits a video into small files, so the player can change quality.
- Idempotent
- Doing it twice has the same result as doing it once. This makes a retry safe.
- Ladder
- The full list of quality levels for one video. Each level is called a rung.
- Remote flag
- A setting that the server can change. It can turn a feature on or off without a new release.
- Repository
- The class that reads and writes data for the rest of the app. It hides whether the data comes from the network or the database.
- Rollback
- Going back to the old behavior after a problem. A build on a user's phone cannot be taken back, so teams use a kill switch.
- Staged rollout
- A release to a growing share of users, not to everyone at once. It limits the harm of a bad release.
- ViewModel
- A class that holds the state of one screen. It survives a screen rotation.
Verification notes (last reviewed 14 Oct 2026)
- I read 13 official pages: the Media3 guides (background playback, downloading, DRM, release notes), Android foreground service timeouts and Data Saver, Apple's HLS pages, the download-session reference, and the Play and App Store release help.
- Documented: a download cache should not evict. The 6 hours in 24 limit for data-sync services on Android 15 and later. Segments of 6 seconds and I-frame playlists in Apple's HLS authoring spec. Only on-demand HLS can be saved.
- Documented: a halted Play rollout keeps the build on devices that have it. An App Store phased release can be paused for up to 30 days. Neither page says installed copies can be reverted.
- Documented: a ViewModel is cleared when its owner leaves the back stack.
NWPath.isConstrainedmeans Low Data Mode. A force-quit cancels active background downloads on iOS. - My design, not from docs: the playback call, server-stamped progress, the 3 second preload, the H.264 rung ask, the rollout plan, the level advice and the staff answer.
- My assumptions, not measurements: 730 / 8 is 91 KB/s, about 330 MB an hour. 2,000 / 8 is 250 KB/s, about 900 MB an hour.
- Not verified: that Media3 restarts downloads through its scheduler after the timeout, and iOS background audio behavior (audio session plus background mode).
- The follow-up questions are my reconstruction of challenges that public prep material reports. They are not transcripts of real rounds.
Questions or corrections?
Add them to the discussion thread for this case on GitHub. To post, you need a free GitHub account. What you write there is public and follows GitHub's terms. Good answers are added to this page.
Keep reading
Get the free one-page cheat sheet
One page: the five steps, a 45-minute time plan and two checklists. Print it or keep it on your phone.
We email you the cheat sheet after you confirm your address. You can also open it now from the Start here page. You also get a short email each week with a follow-up round, and a note when a new case is published. Unsubscribe any time. Privacy.