skip to content

Persistent Store Choice

The persistent store is the source of truth the UI observes: an embedded relational database, a key-value store, a document store or plain files, chosen by query and size needs. Interviewers ask why.

on this pageshow

explore

questions

6

In a mobile language-learning app, which data deserves the persistent store, and which can live in a disposable cache?

level: juniorimportance: must knowfreq 52%

answer

  1. what is lost if it vanishes
  2. the only copy until synced
  3. needed offline, though re-downloadable
  4. the cache folder is the OS's
  5. write it when it happens

basics

~20 s

Persist anything that is the only copy (grades, progress, streaks, settings) or that the user needs offline (downloaded lessons, the course list); cache only what exists for speed and can be re-fetched with nothing lost.

solid answer

~40 s

I ask one question per piece of data: if it vanished, would the learner lose something? Card grades, lesson progress, the streak and settings are the only copy until the server has them, so they go in the persistent store, written as they happen, because the OS may end a backgrounded process at any time. Lesson packs the learner downloaded for a flight can be downloaded again, but the learner is counting on them offline, so they are persistent too and never sit in the OS's purgeable cache folder. Course thumbnails, the leaderboard and catalogue pages only make screens faster; they belong in a cache the app can lose at any moment and rebuild. Nothing in a cache may ever be the only copy.

go deeper

for a junior

Recall the one-line test: if losing it costs the user something, persist it; if losing it only costs a re-fetch, it may be a cache.

for a middle

Explain why offline needs and user-requested downloads push re-fetchable data into the persistent store, and why fresh user input is written as it happens.

for a senior

Show what goes wrong when the line is drawn badly: packs vanishing after the OS purges space, grades lost to a background kill, a store that grows without bound.

for a principal

Turn the test into an app-wide data policy: categories of data, where each lives, how long it is kept and who signs off on new persistent data.

Every mobile design round reaches the moment where the interviewer points at the diagram's "local storage" box and asks what is in it. A strong answer separates two things that both live on the phone's disk: the **persistent store**, which the app must never lose, and a **cache**, which exists to make screens faster and may vanish at any time. ## The test: what is lost if it disappears Ask three questions of each piece of data: 1. **Is the phone holding the only copy?** Anything the learner created or earned on the device, such as grades given while offline or today's progress, exists nowhere else until the server acknowledges it. 2. **Does the learner need it without a network?** An offline-capable app must at least be able to read its core data with no connection, so server data the screens show offline has to be stored, even though the server also has it. 3. **Is it only there for speed?** Images, rendered thumbnails and pages fetched for browsing make screens appear sooner; losing them costs a re-fetch, not data. A yes to the first or second question means the persistent store. Only a yes to the third alone means a cache. Data can also move between the two: a course the learner merely browsed is cache, but the moment they enrol and expect to study it offline, its lessons belong in the persistent store. ## The language-learning app's data, sorted | Data | Only copy? | Needed offline? | Where it goes | |---|---|---|---| | Card grades and due dates | Yes, until synced | Yes | Persistent store | | Lesson progress, streak, completions | Yes, until synced | Yes | Persistent store | | Settings (language, daily goal, reminders) | Often yes | Yes | Persistent store | | Downloaded lesson packs with audio | No, re-downloadable | Yes, that is why they were downloaded | Persistent files | | The course list and lesson texts | No | Yes | Persistent store, refreshed from the server | | Catalogue thumbnails, leaderboard pages | No | No | Disposable cache | ## Re-downloadable is not the same as cache The trap in this question is the downloaded lesson pack. It can be fetched again, so it looks like cache. But the learner pressed download precisely so it would be there on the plane. Both native platforms give an app a cache folder that the OS may delete to recover space when storage runs low, without promising when. A pack kept there can disappear the night before a flight. The rule: - **Data the user explicitly asked to keep** is persistent, even when the server can send it again. - **Data the app fetched on its own** to save time is a cache candidate. - Persistent but re-downloadable files can still be excluded from device backup; on one platform the guidance asks for exactly that, to keep backups small. ## Write it when it happens Persisting the right data is only half the answer; *when* it is written matters as much. A mobile OS may end a backgrounded process at any time to reclaim memory, and the app is not promised a chance to run code first. Holding today's grades in memory and saving them "at the end of the session" means a learner who switches to a message mid-lesson and comes back an hour later may find the grades gone. The persistent store should receive each grade when it is given, from a write that runs off the UI thread so the lesson stays smooth. ## What a cache is allowed to be A disposable cache can be small, can be wiped on logout, can be emptied by the OS and can be cleared from a settings screen, and the app must simply re-fetch or show a placeholder. That freedom is exactly why nothing in it may be the only copy of anything. If emptying the cache ever loses a grade or breaks an offline lesson, something persistent was put in the wrong place. ## Common mistakes - Treating "the server has it" as "no need to store it", which breaks the first offline launch. - Putting user-requested downloads in the OS's purgeable cache folder. - Holding fresh user data in memory and saving it later in a batch. - Persisting everything forever, so the store fills with pages nobody will reopen and grows without bound. - Copying browsed catalogue pages into the persistent store "just in case", which turns it into a cache that nothing ever evicts.

  • The server already has the learner's progress. Why persist it on the phone at all?
    Because the app must work offline: screens read progress from the local store, and grades given on a plane exist only on the phone until they sync. Until the server acknowledges them the phone holds the only copy. Synced progress is kept as well, so the next offline launch can still show it.
  • What should the learner notice when the OS has emptied the app's cache folder overnight?
    Nothing beyond slightly slower screens: thumbnails and catalogue pages are fetched again on demand, and while offline the screen shows placeholders. If emptying the cache loses a grade or breaks a lesson, persistent data was stored in the wrong place, and that is the bug to fix.

A traveller's own notebook versus the hotel's free city map: the notebook is the only copy and must be kept safe, the map can be thrown away and picked up again, but the guidebook they deliberately packed for a hike has to stay in the bag even though any shop sells another.

  • Data the server also holds never needs to be stored on the phone.
  • Downloaded offline lessons are just cache, so the OS's cache folder is fine for them.
  • The OS never deletes files from the app's own cache folder.
  • Today's grades can wait in memory and be saved once at the end of the session.
  • A cache entry may be the only copy as long as it is rarely evicted.
open as a page

In an offline language-learning app, which store kind would you choose for flashcards, progress, settings and lesson audio, and why?

level: middleimportance: must knowfreq 58%

basics

~10 s

Choose by each data's queries and size: cards and progress in an embedded relational database indexed by due date, settings in a key-value store, and audio as files that a database row points to.

open as a page

In an offline language-learning app, should the local database store each server response whole or normalize it into records, and why?

level: middleimportance: should knowfreq 48%

basics

~20 s

Normalize data that screens query or the device edits into records keyed by stable ids, so one write updates every screen observing it; store whole only what is read whole, replaced whole and never edited on the device.

open as a page

In an offline language-learning app with 20,000 flashcards, the due-today screen gets slower as the deck grows; what is happening, and what fixes it?

level: seniorimportance: should knowfreq 44%

basics

~20 s

Without a matching index the query scans and sorts every card, and the observing screen repeats that after each grade; a composite index on deck and due time turns it into a short, already ordered range read.

open as a page

In an offline language-learning app, finishing a lesson updates its progress, the streak and fifty card due dates; how should the local store write them?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Compute the changes first, then write them in one short transaction in one store, guarded by a unique completion id; a kill leaves all or none of it, and observing screens see one consistent change.

open as a page

In an offline language-learning app, lesson packs carry about 60 MB of audio each; how should the app store them and handle a nearly full phone?

level: seniorimportance: nice to knowfreq 36%

basics

~20 s

Keep audio as files in the app's persistent private storage with a database row per pack, mark a pack ready only after its file is complete, check free space before downloading, and let the learner see and remove downloads.

open as a page