skip to content

In a health-diary app, when an update changes the local data's shape, which on-device data must be migrated and which may simply be dropped?

level: juniorimportance: should knowfreq 35%

answer

  1. an update swaps code, not data
  2. who else could rebuild this row?
  3. typed only on the phone
  4. a server copy can be refetched
  5. keep disposable apart from irreplaceable

basics

~20 s

Data that exists only on the phone (diary entries, unsent edits, the user's settings) must be migrated. Copies the server or the app bundle can rebuild, like a downloaded reference list, may be dropped and refetched.

solid answer

~40 s

An update replaces the app's code but leaves its data files where they were, so the new build opens a store written in an older shape. I sort that data by one test: could anything else recreate it? Diary entries kept only on the phone, edits not yet uploaded and the reminder times the user chose exist nowhere else, so a migration must carry them forward; deleting them is permanent. Cached copies of server data, like a downloaded medication reference list or the last search results, can be dropped and refilled from the network, and migrating them costs code and tests for no gain. Keeping the two kinds in separate files or tables, each with its own version, lets the app wipe the disposable one freely while the irreplaceable one gets the careful path.

go deeper

for a junior

Recall that an update keeps the old data files, and sort each kind of data by whether anything else holds a copy before deciding to migrate or drop it.

for a middle

Explain the cost on each side: a migration is code you write, test and keep forever, while dropping refetchable data is free; show how separate stores with separate versions make the choice mechanical.

for a senior

Show the edge cases: opted-in backup that lags behind, unsent edits, bundled lookup tables, and the purgeable cache folder that must never hold the only copy.

for a principal

Frame it as a data-classification policy for the whole app: every new table declares whether it is rebuildable, and that label decides its migration duty.

## What an update does to stored data Installing a new build of a mobile app replaces the **code** but keeps the app's private **data files**: the local database, key-value files and downloaded content stay where they were (removing the app deletes them; updating it keeps them). So the first time the new build runs, it opens a store written by an older build, in an older **schema** (the shape of tables, columns and stored records). If the new code expects a column the old file lacks, reads fail or the app crashes. A **migration** is the code that rewrites the stored data from the old shape to the new one. Before writing any, a designer asks a simpler question about each kind of data: *does anything other than this phone hold a copy?* ## Sorting data by whether it can be rebuilt In a health-diary app where entries stay on the phone until the user opts into backup, the answer splits cleanly: | Data | Other copy? | On a schema change | |---|---|---| | Daily symptom and medication entries | none until backup is on, and backup may lag | **migrate** | | Edits made offline, not yet uploaded | none by definition | **migrate** | | Reminder times and other user choices | none | **migrate** | | Downloaded medication reference list | the server | **drop and refetch** | | Thumbnails, last search results | the server or the originals | **drop** | | Lookup tables shipped inside the app | the new app bundle | **replace** from the bundle | The rule behind the table: - **Device-only data is migrated**, step by step, because deleting it is permanent. A user who loses three years of symptom history does not care that the app now launches cleanly. - **Restorable data is dropped**: wiping a cache and refilling it is cheaper and safer than writing, testing and maintaining a migration for it. A dropped cache simply behaves like a first launch for that screen. - **Data the user has opted to back up is still treated as device-only** until every row is confirmed on the server; entries written since the last successful upload exist in one place only. ## Making the split structural The decision is easiest to keep when the storage layout mirrors it: 1. Put irreplaceable data in one store and disposable caches in another file or set of tables. 2. Give each its own **schema version** number. 3. On a version mismatch, the cache store is deleted and recreated empty; the irreplaceable store runs its migration chain. This also protects against a quieter failure: the OS's purgeable **cache folder**. Both native platforms document that the system may delete an app's cache directory to free storage, so nothing there may be the only copy of anything. The diary database belongs in ordinary app storage; only the refetchable copies belong in the cache folder. ## A worked example Suppose the next diary release renames fields in the downloaded medication reference list and adds a `severity` value to each symptom entry. The two changes get opposite treatment: - The reference list's version no longer matches, so the app deletes that store and refetches it on the next connection; until then the medication picker falls back to the names already written in the user's own entries. - The symptom entries get a migration step that adds `severity` with no value, meaning *not recorded*, rather than inventing a default the user never chose. Neither change needed a judgment call at release time, because the classification was made when each store was designed. ## Common traps - Treating every table alike, so a cache gets a hand-written migration nobody needed, or, worse, the diary gets the cache's delete-and-recreate treatment. - Resetting user settings on every schema change because they look small; a lost reminder schedule is a missed dose. - Assuming an update starts from an empty store, which hides the problem until real users with old data upgrade. - Storing the diary in the cache folder because it is convenient, then losing it the day the phone runs low on space. ## What the interviewer is checking The question looks basic, but it sets up every later decision on migrations: the step chain, what to do when a step fails, and when a destructive fallback is acceptable. A candidate who classifies data by *who can rebuild it* can answer all of those consistently, because the answer to "may we delete this?" was decided before any migration code was written.

  • The diary keeps its entries and a downloaded medication reference list in one database. What changes if you split them?
    Each part gets its own file and version. A reference-list schema change then means deleting that file and refetching, with no migration code at all, while the entries file runs its careful step chain. It also means a failure in one cannot take the other down, and the reference list can live where the OS may purge it.
  • Is it ever right to drop data the user typed rather than migrate it?
    Only when every row is confirmed on the server and can be pulled back, and even then only if a resync is cheap enough to accept. Anything written since the last confirmed upload exists only on the phone, so for an app whose backup is optional the default must be to migrate.

  • Installing an update gives the app a fresh, empty local database.
  • A cache table must be migrated like any other, or its data is lost for good.
  • Once the user has turned on backup, wiping local entries on upgrade is harmless.
  • The cache folder is a fine home for the diary database because updates keep it.
  • Settings are trivial, so resetting them on each schema change is acceptable.