skip to content

In a mobile news app read on commutes, how should fetched feed pages be stored so a relaunch with no signal shows articles at once and paging resumes?

level: seniorimportance: must knowfreq 55%

answer

  1. the list reads the store only
  2. the network writes, never renders
  3. page and next cursor, one transaction
  4. store the server's order yourself
  5. a cached tail is not the end

basics

~20 s

Write each page into a local database and render the feed only from it, saving the articles, their server order and the next cursor in one transaction. A relaunch then paints the stored window at once and continues from that cursor.

solid answer

~50 s

The local database is the feed's single source of truth: the list observes a query over it, and the network only writes into it. Each fetched page is stored in one transaction as article rows plus a page record holding the cursor that requested it, the next cursor and a fetch time, so a kill can never leave articles without their cursor or a cursor without its articles. The order is the server's, so each row keeps a page sequence and position; publish time is not a ranked feed's order. On relaunch the list renders the stored window from disk before any request, and scrolling past it requests the stored next cursor. With no signal the bottom shows an offline retry row, not the end; whether to refresh the head on launch is a separate freshness decision.

code

json · 11 lines
json
{
  "feed_page": [
    { "feed": "home", "page_seq": 0, "request_cursor": null, "next_cursor": "kQ7vX2pL", "fetched_at": "2026-10-06T07:41:12Z" },
    { "feed": "home", "page_seq": 1, "request_cursor": "kQ7vX2pL", "next_cursor": "Zp41mAe9", "fetched_at": "2026-10-06T07:43:55Z" }
  ],
  "feed_item": [
    { "feed": "home", "article_id": "art-58213", "page_seq": 0, "pos": 0, "headline": "Rail strike talks resume", "publisher": "pub-114", "image_url": "https://img.example/58213-w400.jpg" },
    { "feed": "home", "article_id": "art-58197", "page_seq": 0, "pos": 1, "headline": "Council approves new cycle lanes", "publisher": "pub-032", "image_url": "https://img.example/58197-w400.jpg" },
    { "feed": "home", "article_id": "art-58240", "page_seq": 1, "pos": 0, "headline": "Storm warning for the coast", "publisher": "pub-007", "image_url": "https://img.example/58240-w400.jpg" }
  ]
}

go deeper

for a junior

Recall that fetched pages are saved on the phone so the feed appears at once after a relaunch, and that the list shows what is saved rather than what just arrived.

for a middle

Explain the page record, why articles and cursor commit together, and why the order is stored explicitly rather than recomputed from publish times.

for a senior

Walk the relaunch with no signal and a week-old cursor, the kill between two writes, and the offline tail versus the end, keeping head freshness as a separate decision.

for a principal

Decide whether every feed surface in the app shares one stored-window schema and repository, and what that costs when surfaces need different window sizes and orders.

## Why the store, not memory or the network, feeds the list A commuter opens the news app on the platform, reads a few screens, loses signal in the tunnel and opens the app again later, perhaps after the system has killed the process. Two requirements follow: the feed must appear **at once** on relaunch, with or without signal, and scrolling must **continue** from where the stored pages end. Memory cannot meet either; it is gone after a kill. Rendering network responses directly and also saving them "for offline" creates two sources that disagree whenever a save fails or lags. The shape that meets both is the one recommended in one native platform's architecture guidance and applicable everywhere: the **local data source is the single source of truth**. The list reads only from a query over the local database; the network's only job is to write fetched pages into it, and the list updates because the query result changed. A related guide describes exactly this for paged lists: the app pages out of the local database and asks the network for more only when the stored data runs out. ## What a stored page contains The window is stored as two kinds of record: the articles, and a record per page that holds the paging state. | Field | Why it is stored | |---|---| | `article_id` | Stable identity: an article appearing again is written over, not added twice | | `page_seq`, `pos` | The server's order, assigned as pages arrive; the feed is ranked, so it cannot be recomputed later | | Card content (headline, publisher, image URL) | Enough to render the card with no network | | `request_cursor` | The cursor that fetched this page; needed if the page must ever be fetched again | | `next_cursor` | The cursor that continues after this page; null once the contract signals the end | | `fetched_at` | Lets the app judge how old the window is on relaunch | Images themselves sit in the image cache; the article row keeps only their address. ## Writing a page Each successful response is written in a single local transaction: 1. Upsert the page's articles by `article_id`, with the next `page_seq` and their positions. 2. Insert the page record with its `request_cursor`, `next_cursor` and `fetched_at`. 3. Commit. The list's query re-runs and the new cards appear. The transaction is the point. Store the articles and the cursor in separate writes and a kill between them leaves either articles with no way to continue past them, so the page gets fetched again, or a cursor pointing past articles that were never saved, so a page is silently skipped. One platform's paging guide makes the same recommendation: store the loaded data and the next key in one transaction so that they are always consistent. ## Relaunch, step by step 1. **Render from disk.** Before any request, the list shows the stored window in `page_seq`, `pos` order. With no signal, the reader can still read every stored card. 2. **Restore the load state** from the last page record: `idle(next_cursor)`, or `ended` if the end was recorded. 3. **Continue at the bottom.** When the reader nears the end of the stored window, request with the stored `next_cursor` and write the result as the next page. 4. **No signal at the bottom:** show an inline offline row with a retry action. The end of the stored window is not the end of the feed. 5. **Old window:** how long a cursor stays valid is the API contract's decision. If the server rejects the stored one after days away, discard it and page from the head, keeping the cards on screen meanwhile. Whether the app also refreshes the top of the feed on launch, and how fresh items merge above the reader, is the refresh and gap design; the stored window gives it something to show while that happens. ## Where it goes wrong - **Ordering by publish time.** A ranked feed mixes publishers and topics; sorting the cache by date shows a different feed from the one the reader left. - **Rendering the response, saving later.** The list and the store diverge, and the relaunch shows something other than what the reader last saw. - **Treating the cached tail as the end** when offline, which tells a commuter in a tunnel that they have read everything. - **Putting the window where the OS may purge it** without planning for that. Both platforms may delete their cache folder when storage runs low; that is acceptable for re-fetchable pages only if the design expects to relaunch with nothing stored. - **Letting the window grow forever.** The stored window needs a cap and an eviction rule; that is its own decision.

  • Why not render the network response directly and save it in the background?
    Then the list has two sources: what arrived and what was saved. They disagree whenever the save fails, lags or is cut off by a kill, and the relaunch shows something other than what the reader last saw. Rendering only from the store costs one local write and an observed query per page, and buys a single answer to what is on screen.
  • The relaunch comes a week later. Is the stored next cursor still usable?
    Possibly not; how long a cursor stays valid is the API contract's decision. Try it, and if the server rejects it, drop the stored cursor and page from the head, keeping the cached cards on screen meanwhile. A week away also makes the top of the feed stale, and replacing it without moving the reader belongs to the refresh and gap design.
  • Can the stored window live in the OS's purgeable cache folder?
    It can, since every page can be fetched again, but then the design must expect it to vanish: on both native platforms the system may delete that folder when storage runs low. The relaunch then opens with nothing cached and fetches the head. If an instant offline relaunch is a hard requirement, keep the window in the app's persistent storage and bound its size yourself.

  • An in-memory page list is enough to show articles after an offline relaunch.
  • The articles and the next cursor can safely be saved in separate writes.
  • Sorting the cached articles by publish time rebuilds the feed's order.
  • Rendering responses directly while also caching them keeps the two consistent.
  • With no signal, the end of the cached window is the end of the feed.