Build it. The database schema, API, code and platform limits for a news feed are on a separate page: Build it: a news feed on Android and iOS (10 min read).
Try it. See why a page number repeats posts when the feed changes, in the pagination race.
How to read this. This page follows a 45-minute round (the length I assume), in the order I would spend it. The schema, API and code are in the build guide. In a round I would draw them only if asked. The follow-up questions below are my reconstruction of the kinds of challenges that public prep material reports. They are not transcripts of real rounds.
TL;DR. My answer in four points.
Patterns in this round.
- Outbox (a like is saved first and sent later)
- Repository (the screen reads the saved page, and the network writes into it)
- Layered cache (the saved page is shown first)
More in design patterns in mobile rounds.
- The local database is the source of truth (the one copy the app trusts). The screen only reads from it.
- Pages come by cursor (a saved place in the list, given by the server). The feed order lives in its own table, so an edited post never moves.
- A like sets a state and shows at once. It stays pending until the server confirms it. The outbox (a saved list of unconfirmed work) sends it later.
- A refresh must never undo a pending like.
- On iOS: the same design. SwiftData or Core Data holds posts and order, I write the cursor loader, and I send the like outbox myself.
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: Fix the scope early, leave video and accounts for later, and name what the phone does.
A prompt I would expect: "Design the home feed for a social app." I ask five questions, each with a default:
- What is in a post? Text, images, author, counts.
- Who sets the order? The server ranks the posts, so the app cannot sort them.
- Which actions? Scroll, pull to refresh, like and unlike.
- Offline? Yes: the last feed, and likes wait in the outbox.
- New posts live? A pill (a small "New posts" button), never an insert that moves the list.
| In scope | Out of scope | Left for later |
|---|---|---|
| Server-ranked feed with images | Ranking method | Video in posts |
| Endless scroll, pull to refresh | Ads | A second phone |
| Like and unlike, also offline | Stories | Signing out and switching accounts |
| Last feed on open, "New posts" pill |
| What the phone does | Requirement at risk | Deep dive |
|---|---|---|
| Stops the app process without warning | A tap on like must not be lost | Client structure (3), pending like (4.2) |
| Limits background work | A like in the outbox still reaches the server | Pending like (4.2) |
| Loses the network during a request | No repeated or missing posts, no flipped like | Data and contracts (2), pending like (4.2) |
| Runs on a battery and a data plan | Images use the most data | Device numbers (2), paging (4.1) |
Your decision. The scope follow-up I expect: "Make new posts appear live, and add comments and video." Which do you keep?
First idea, and why it fails. Say yes to all three.
- A live insert moves the list while the user reads.
- Comments need their own paged list.
- Video needs different loading code than images.
What I would say. The pill stays. It shows a count and inserts nothing until the user taps it. I set comments and video aside and say why. I reject live insertion.
The follow-up question I expect: "Live is the point of a feed."
I keep the pill. Only the insert waits for a tap.
Say this. "The feed, paging and likes are in. Video, a second phone and switching accounts each change the data shape or the write path, so I leave them for later. Tell me if you want one earlier."
45-minute plan
| Minutes | Step | Shown by the end | Skip if short of time |
|---|---|---|---|
| 0 to 4 | Scope and constraints | In and out list, phone behaviors | Fewer questions |
| 4 to 14 | Data and contracts | Two tables, cursor, four calls | The numbers |
| 14 to 22 | Client structure | Layers, who owns the like | One line per layer |
| 22 to 40 | Solve the hard part | Refresh, pending like | Paging in three sentences |
| 40 to 45 | Failures, release and rollback | Top failures, the flag, metrics | Two failures and the flag |
2. Data and contracts (minutes 4 to 14)
In short: Posts and order sit in separate tables. Load pages by cursor, never by offset (a page number).
Your decision. The server ranks the feed, and posts change while the user reads. What do you store, and how do you ask for the next page? One option is a rank on each post with offset paging. The other is post data and order apart, with a cursor.
First idea, and why it fails. Put a rank on the post row and ask for page two with an offset. This fails in two ways:
- The server changes the ranking, so an update to a post changes its position and the user sees it jump.
- When new posts arrive between two requests, an offset skips some posts and repeats others.
What I would say. The screen reads only the local database. I keep two tables:
- Posts hold content and like state.
- Feed items hold only the position in the server's order, written when a page is stored.
Updating a post never changes the order. The app sends the cursor back unread for the next page. I reject sorting by time, because a ranked feed is not in time order.
The follow-up question I expect: "The server changes the ranking between page one and page two. Does the cursor save you?"
Not by itself. A cursor stops a new top post from moving page two. It does not stop a new ranking from repeating a post. The tables are in the build guide.
- Either the server keeps the ranked list fixed behind the cursor, or the app removes repeats by post ID. I ask which one the backend does, and remove repeats anyway.
The contract in three lines:
- Page: a cursor and a limit in, items and the next cursor out. No cursor means the first page.
- Head check: the newest post ID I hold in, a count of newer posts out. It feeds the pill.
- Like: PUT sets liked, and DELETE sets not liked. Both are safe to retry (doing either twice has the same result as doing it once).
These numbers are assumptions, not measurements:
| Assumption | Arithmetic | What it settles |
|---|---|---|
| A page is 20 posts of about 2 KB of text; I keep 300 rows | 40 KB a page, 600 KB for 300 | Limit by row count, not by byte size. Images are what I limit |
| One image per post, about 150 KB at view size | 20 x 150 KB is 3 MB a page; ten pages, 30 MB | No image prefetch (loading ahead of need) on cellular. Prefetch by position, not by page |
| A fast swipe is 4 rows a second; a page takes about 500 ms | 10 rows ahead is 2.5 s of time, five times the request time | A distance of 10 is enough. More uses data for no gain |
3. Client structure (minutes 14 to 22)
In short: A repository below the screen owns the like and the list.
Your decision. Who owns the like and the paged list? Three choices: the feed screen's ViewModel (the object that holds screen state), a service, or a repository (the code that owns the data) below the screen.
First idea, and why it fails. The ViewModel. It holds the screen state, so it calls the API from viewModelScope and keeps the posts in memory. But a ViewModel lives only as long as its screen. When the user leaves the feed, it is cleared, and that cancels a like still in progress. When the OS stops the process, nothing remains.
Android's docs answer process death with SavedStateHandle for small UI state (saved state).
What I would say. Ownership goes below the screen. A like is a write to Room (Android's database library) plus a WorkManager job (Android's tool for work that outlives the screen).
Scheduled work is documented to persist across app restarts and device reboots (persistent work). The ViewModel only asks the repository to record the like.
I reject a service and an app-wide coroutine scope: if the process dies, a like in either one is lost, because nothing is saved.
The follow-up question I expect: "Two screens show the same post and one likes it. How does the other know?"
Both watch the one posts table, so the row change reaches both.
More links
- UI to Image pipeline: urls
- Image pipeline to Image CDN: fetch
- Feed repository to Page loader: load
- Page loader to REST API: pages
- Local database to Like queue: taps
- Like queue to REST API: send
The screen and ViewModel are the UI layer, and FeedRepository is the data layer. A domain layer is recommended in big apps, for logic that several ViewModels share (recommendations). With one feed I skip it.
The rule: workers call FeedRepository, not the DAO (the database access object) or the API.
4. Solve the hard part (minutes 22 to 40)
In short: Refresh loads new data before it replaces old data. A pending like wins over server data.
4.1 Refresh and paging (minutes 22 to 31)
Your decision. The user pulls down to refresh, or opens the app with an old cache (the saved copy of the feed). What happens to the list on screen until the new page arrives?
First idea, and why it fails. Clear the table, show a spinner, then fetch. If the request then fails, in a tunnel or with a server error (a 5xx code), the user sees an empty screen.
What I would say.
Say this. "Refresh fetches first and replaces second. The old feed stays on screen. When page one arrives, one transaction (all its changes succeed, or none do) clears the old order. It upserts the posts (inserts them, or updates them if they exist) and stores the new order. So nobody sees half a list."
The Paging 3 (Android's paging library) network-and-database sample uses this order. The network call comes first. Then one transaction clears the data on a refresh and inserts the new data (guide).
On open, I show a cache under ten minutes old as it is and refresh an older one in the background. Ten minutes is my example; the guide's sample uses one hour.
The follow-up question I expect: "The cache is two hours old when the app opens. Spinner or old feed?"
The old feed, refreshing in the background.
Images are the slowest part of a row, so I also say this:
- Ask the CDN for a size that matches the view. Never decode a full-size image for a thumbnail.
- Start image loads by row position, about two screens ahead. Cancel loads for rows the user has scrolled past.
- Skip image prefetch on cellular or in data-saver mode.
If a page request fails halfway down, the list ends with a retry row, never a silent stop.
4.2 The pending like (minutes 31 to 40)
Your decision. A refresh arrives while a like still waits for the server. Does the server's copy of the data win, or the user's tap?
First idea, and why it fails. Let the server's copy replace the row. But the server made that copy before the like arrived. The heart turns off, then turns on again when the write finishes.
A toggle endpoint is worse. If the response is lost and the app retries, the like flips back.
What I would say.
Say this. "A like sets a state, never a toggle. In one transaction I set liked, change the count and mark it pending, so the heart fills at once. I add a PUT to the outbox. Server data never replaces a pending row. The local change wins until the server confirms it. Then I store the server's count. Rapid taps merge: one pending change per post, last state wins."
A temporary failure is retried with backoff (wait longer after each failure). A permanent rejection undoes the like. That split is my own classification. A retry is safe because the call sets a state. The merge code and the retry rules are in the build guide.
The follow-up question I expect: "The OS stops the process right after the tap."
The pending flag and the outbox entry are saved, so the like continues on the next launch, as in the chat app.
The follow-up after that: "On the next launch the stored like gets a 401. Or a 404, because the post was deleted."
- A 401 is not a permanent rejection. I keep the row pending, refresh the token once and retry. If the refresh fails, the likes wait until the user signs in again. I do not undo a tap that was valid.
- I would store the account ID on each outbox entry. Only that account's session may send it. If another account is signed in, the entry waits or is deleted, never sent as the new user.
- A 404 or 410 means the post is gone. I drop the outbox entry and remove the post on the next refresh. A retry cannot fix it.
If I am cut off, I answer first:
Say this. "Yes, a second refresh while the like is pending is harmless, because pending rows keep their local state. I was in the middle of the write path, and I will finish it."
4.3 Where iOS changes the design
The data model and API stay the same. The Swift loader is in the build guide.
- Database.
PostandFeedItemare SwiftData or Core Data models. The list reads them with@Querysorted by position, or withNSFetchedResultsControllerin UIKit. - Refresh. The same rule: fetch first, then one save on a background context deletes the old order, upserts the posts and writes the new order.
- Paging. There is no Paging library, so I write a loader that starts near the end of the list. It keeps one running task and shows a retry row when a page fails.
- Likes. There is no WorkManager, so I send the outbox myself.
- I drain it when the user taps, when the app returns to the foreground and when the network comes back.
beginBackgroundTaskasks for a little extra time to finish a request in flight.- I do not count on a background run after a force-quit (the user closes the app), and I say so.
- Images. I use a proven library such as Nuke or Kingfisher. Apple says prefetch is not called for every cell, so a row must work when its image is missing.
5. Failures, release and rollback (minutes 40 to 45)
In short: I cannot remove a build from phones, so I go back to the old behavior with a flag.
| Failure | User sees | Data holds | Recovery |
|---|---|---|---|
| Process dies mid-write | The heart stays filled | Pending flag, outbox entry | The like resumes next launch |
| Lost acknowledgement | One like, not two flips | Pending flag | Same PUT sent again; it sets a state |
| Duplicate delivery | One post | Feed items keyed by feed and post ID | Upsert, no second row |
| Out-of-order delivery | The loaded list holds still | Stored order | Offer the new order with the pill or on refresh |
| A page arrives after a newer refresh started | The list holds still | A generation number for each refresh | Drop a page that belongs to an older generation |
| Unlike while the like is still in flight | The heart shows the last tap | Pending flag | Wait for the PUT, then send the DELETE, so the server never ends on the old state |
| Long offline gap | The old feed, then page one | Stored cursors | An expired cursor restarts from page one |
| Sign-in expired with likes waiting | Hearts stay filled | Pending flags, outbox entries with account ID | Refresh the token once. If that fails, ask to sign in. Entries wait |
| Permanent rejection | The like is undone with a small error | Cleared flag | Show the error, no retry |
Rows not linked to a source are my design choices. Sources are in Further reading.
Release facts:
- A Play staged rollout (a release to a growing share of users) can be halted. Users who have the update keep it. Play help says to roll out a new release with a fixed app bundle (Play help).
- An App Store phased release can be paused for up to 30 days (Apple).
- Neither page describes removing a build that is already installed.
- Old versions stay installed, so the server keeps accepting their cursors and requests.
- The new feed code ships behind a server-controlled flag (a setting the server can change without a new release). That flag is my kill switch (it turns the new code off), the only rollback that reaches installed apps.
- A database schema change cannot be turned off with a flag, so it ships one release before the code that needs it.
Say this. "I cannot remove a bad build from phones, so the rollback is the flag plus a fixed build. I would watch time to first content, failed likes, and repeated or missing posts. I left out ranking, ads, video and stories."
6. Follow-ups that change a constraint
In short: Six prompts, each with a strong and a weak answer.
They are practice prompts, not a claim about what any interviewer asks.
- Someone swipes through 300 posts on a weak connection. - Strong: one page request at a time, a retry row on failure, and prefetch ten rows ahead. No image prefetch on cellular, and a row limit that removes the oldest. - Weak: "load everything faster."
- Add video to posts. - Strong: autoplay follows the most visible item and pauses off screen, as in the autoplay section of the video app. - Weak: the video as one more image.
- A second phone. - Strong: the server is the authority for the count and the liked state. The pending flag covers only this phone's unconfirmed tap. A refresh brings in the other phone's like. - Weak: copying the database file between phones.
- Someone signs out and another signs in. - Strong: the cache and pending likes belong to the old account, so I send or delete them before the switch. - Weak: clearing the feed and forgetting the outbox.
- After release, users report repeated posts. - Strong: switch the flag back to the old code, pause the staged release, read the rates of repeated and missing posts, and ship a fix. - Weak: "remove the release."
- The backend changes the cursor format. - Strong: the app never reads the cursor. But old cursors are saved in the database, and old apps still send theirs. The server accepts both, or the app deletes stored cursors when it updates. - Weak: assuming that everyone updates.
7. What changes by level
In short: The levels differ in who raises the problem first.
These levels are my own reading of the standard, drawn from vendor and prep material, not any company's rubric.
- Mid-level: the database as the source of truth, cursor paging, basic image caching. I want to hear: "I will cache the feed in Room."
- Senior: feed order in its own table, optimistic likes (shown at once) that are safe to repeat, a refresh that clears only after success, and the pending-like merge. I want to hear: "I will keep order in its own table so an edited post never moves."
- Staff: ranking changes in a session, matching data across devices, flags, metrics, and a plan to share the feed module across screens. I want to hear: "I would ship the shared module behind a flag and watch time to first content before the second screen."
Common weak answers. They come from public prep material, not a dataset.
- Ten minutes on ranking.
- Naming Paging 3 without saying why.
- A like endpoint that toggles.
- No kill switch.
Staff answer: the decision and the rollout
Decision: one shared feed module, a paging and like layer with a small contract: watch the feed, load more, like, report impressions (a post was seen). Each screen owns its row design.
Alternative: every screen keeps its own feed code. That is faster at first, but the copies later differ.
Revisit trigger: a screen needs rules the contract can only express by checking which screen asks.
Rollout: behind the section 5 flag, then a staged release.
Guardrail: no rise in repeated or missing posts, no drop in like success. Watch time to first content, scroll stutter (dropped frames) and failed likes.
What I read and what is my view: I read the Paging, WorkManager and prefetch facts in the official docs. The ownership model, metrics, rollout order, assumed numbers and level signals are my opinion.
The native vs cross-platform guide shows how I choose between shared code and separate code.
Test yourself
In short: Seven questions from this case. Answer each one out loud first, then open the answer.
1. Why keep post data and post order in separate tables, and load pages by cursor?
The server ranks the feed and posts change while the user reads. With a page number, the same number can point at different posts later, so a post can repeat or be skipped. A cursor says where you stopped. Keeping order apart lets a refresh replace the order without losing the posts.
2. The user pulls to refresh and the network fails. What should be on screen?
The old feed. Refresh fetches first and replaces second. When page one arrives, one transaction clears the old order, upserts the posts and stores the new order, so nobody sees half a list or an empty screen.
3. A refresh arrives while a like still waits for the server. Whose copy wins?
The user's tap. The server made its copy before the like arrived, so replacing the row would turn the heart off and then on again. Server data never replaces a pending row. The local change wins until the server confirms it.
4. Is a like a toggle or a state? What happens on rapid taps?
A like sets a state. In one transaction you set liked, change the count and mark it pending. Rapid taps merge: one pending change per post, and the last state wins.
5. Who owns the like and the paged list, and why not the ViewModel?
A repository below the screen. A ViewModel lives only as long as its screen. When the user leaves the feed it is cleared, and that cancels a like in progress. When the system stops the process, nothing remains.
6. How do you roll back a bad release?
You cannot remove a build from phones. The rollback is a remote flag plus a fixed build. Watch time to first content, failed likes, and repeated or missing posts.
7. On iOS, can a row count on prefetch to have its image ready?
No. Apple says the prefetch callback is not called for every cell. So a row must still work when its image is missing, and show a placeholder until the image arrives.
Further reading (official docs)
- Build it: a news feed on Android and iOS: data model, REST, mediator and loader code, images and platform notes for this case
- Paging from network and database (Android)
- Task scheduling and WorkManager (Android)
- Offline-first guidance (Android)
- Architecture recommendations (Android)
- Staged rollouts (Play Console help)
- Release a version update in phases (App Store Connect help)
Words on this page (20)
- Acknowledgement
- A short reply that says the server got a message. If this reply is lost, the app does not know, so it sends the message again.
- CDN
- Content delivery network. Servers close to users that keep copies of your files.
- Coroutine
- A light background task in Kotlin. It can pause and continue later without blocking a thread.
- Cursor
- A saved place in a list. The server gives it to the app, and the app sends it back to get the next part.
- DAO
- A class that holds the database queries. DAO means data access object.
- Exponential backoff
- Waiting longer after each failure. For example, wait 1 second, then 2, then 4.
- Kill switch
- A remote flag that turns a feature off at once. It is the one rollback that reaches apps that are already installed.
- Optimistic write
- The app shows a change at once, before the server confirms it. If the server says no, the app undoes the change.
- Outbox
- A saved list of changes that the server has not confirmed yet. The app sends them later, even after it restarts.
- Paging
- Loading a long list in small parts. The app asks for one page at a time.
- Prefetch
- Loading data before the user asks for it. It makes scrolling smooth, but it can waste data.
- Process death
- The system ends the process of your app to free memory. Anything that is only in memory is lost.
- 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.
- Room
- Android's library for the database on the phone. You use a DAO to read and write the data.
- Source of truth
- The one copy of the data that the app trusts. In these cases it is the database on the phone, and the screen only reads it.
- Staged rollout
- A release to a growing share of users, not to everyone at once. It limits the harm of a bad release.
- Upsert
- A database step that inserts a row, or updates it if it already exists.
- ViewModel
- A class that holds the state of one screen. It survives a screen rotation.
- WorkManager
- Android's tool for background work that must run later. The work survives when the app closes or the phone restarts.
What I checked and what I did not
- I read the Android pages for Paging with network and database, WorkManager persistent work, offline-first and architecture. They support the refresh order, the one-hour sample window and the claim that scheduled work survives restarts.
- I read the Apple prefetch pages. Prefetch is not called for every cell, and cancelling is optional.
- I read the Play and App Store rollout help. Neither says an installed build can be taken back.
- The numbers are my own assumptions (2 KB a post, 150 KB an image, 4 rows a second, 500 ms a page). I rechecked the sums.
- The 10-minute cache window and the prefetch distances are examples, not documented values.
- I did not verify what happens to iOS background work after a force-quit. I treat it as unreliable.
- No iOS engineer has reviewed the iOS parts yet.
- The follow-up questions and level descriptions are my reading of public prep material. They are not real transcripts or a company rubric.
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.