skip to content

Device Resource Budgets

Battery, cellular data, launch time, frame time and memory are budgets a mobile client spends, and the OS enforces some by killing work. Interviewers probe which budget a design breaks first.

on this pageshow

explore

questions

21

In a personal-budgeting phone app, how should the nightly bank-transaction import be scheduled, and what can the design count on about when it runs?

level: juniorimportance: must knowfreq 55%

answer

  1. the OS picks the moment
  2. constraints, not a clock
  3. earliest start means not sooner
  4. late or never are both normal
  5. show the data's age, refresh on open

basics

~20 s

Submit it as deferrable work with constraints (network, ideally charging) and an earliest start, not a 2 a.m. alarm. The OS may run it hours late or not at all, so show data age and refresh on open.

solid answer

~50 s

A phone OS, not the app, decides when background work runs. So I describe the import as deferrable work: a connected network, charging if the platform lets me require it, and an earliest start after the bank posts the day's transactions. The earliest start is a floor — the OS promises only that the job will not begin sooner — and a constraint that never holds (a phone that is never charged), deep idle, a battery-saving mode or an app the user rarely opens can push it hours late or past the night entirely. So the scheduled import is a head start, not the source of truth: balances carry a last-updated time, the home screen says "updated 9 h ago" and refreshes in the foreground when the user opens the app, and the import is idempotent so a foreground and a background run can overlap harmlessly.

go deeper

for a junior

Recall that the OS, not your code, decides when background work runs, and that an earliest start time means "not before", never "exactly at".

for a middle

Explain constraints such as network, charging and idle, why each one can delay a run, and how the home screen stays honest with a last-updated time.

for a senior

Show the design survives a night with no run: idempotent imports, a foreground refresh on open, a relaxed fallback when the import is overdue, and field measurement of data age.

for a principal

Frame which product promises may rest on device scheduling at all, and push anything time-sensitive, like a budget alert, to the server's push path.

## What "nightly" means to a phone OS A server's cron job runs at 02:00 because the machine belongs to the team that wrote it. A phone does not: the operating system owns the battery, the cellular radio and the CPU, and it runs an app's **background work** only when it judges the cost acceptable for the person holding the phone. The personal-budgeting app therefore cannot say "import the bank transactions at 2 a.m.". It can only hand the OS a *description* of the work and let the OS pick the moment. Both native platforms work this way, and a cross-platform framework's background plugin wraps the same platform scheduler, so it inherits the same rules. ## Describe the job by constraints, not by a clock **Deferrable work** is a unit of work plus the conditions under which it may run. On one platform those conditions are called **constraints** — a connected or **unmetered** network, the device **charging**, the device **idle**, battery not low, storage not low — and the work runs only when all of them hold at once. On the other platform the app submits a task request with an **earliest start**; the documentation says the system "decides the best time" to launch it, and heavier processing is aimed at periods of low activity such as overnight while the phone charges. | What the import needs | How it is described to the OS | Why | |---|---|---| | Data from the bank's aggregator | a connected network | waking without a signal wastes the run | | No overnight battery drain | charging, where the platform supports it | the energy cost lands when power is free | | The bank's posted day | an earliest start after midnight | it means "not sooner", never "at" | | One pending import, not five | one named request, replaced when rescheduled | stops duplicates piling up | ## What the design can count on, and what it cannot It **can** count on a short list: - the work will not start before its earliest start; - it will not start while a declared constraint is unmet — and on one platform, if a constraint stops holding mid-run, the work is stopped and retried once it holds again; - the request outlives the OS reclaiming the app's process, because the OS keeps it (one platform also keeps it across a reboot). It **cannot** count on: - **an exact time** — one platform's documentation is explicit that the system does not guarantee launching the task at the requested date, only that it will not begin sooner; - **that it runs on a given night at all** — a phone that is never charged overnight, lies unplugged in deep idle, sits in a battery-saving mode or belongs to someone who rarely opens the app can see the job late or skipped; - **a long run** — each wake grants seconds to a few minutes, so the import itself must be resumable (a separate question). The principle interviewers listen for: a background schedule is a *request*, and every screen that depends on it must still be correct when the request was never honoured. ## What the user sees when it has not run 1. Store the time of the last successful import alongside the imported data, in the same local write. 2. Render balances with their age ("updated 9 h ago") instead of presenting stale numbers as current. 3. When the user opens the app, refresh in the foreground, where the app may work freely; the overnight run only saves the user that wait. 4. Make the import **idempotent** — each transaction keyed by the bank's own id — so the foreground refresh and a late background run can both land without double-counting a purchase. This turns "the job did not run" from a bug report into a slightly slower first screen. ## Why not an exact-time alarm Teams often reach for an exact alarm at 02:00. On one platform exact alarms exist, but its documentation reserves them for precise user-facing events such as calendar reminders, not for recurring background work, because they wake a device out of its power-saving idle state; that platform's most restricted usage tier is also limited to one alarm a day. It buys precision the import does not need at a battery cost the user pays. The one item in this app that is genuinely time-sensitive — telling a user they are close to the month's budget — is computed on the server and delivered as a push, not left to a device schedule that may not fire. ## The interview answer in one breath Describe the work, not the time; accept that the OS may run it late or not at all; keep the data's age visible; refresh on open; make every run safe to repeat.

  • Why require charging if some users never charge overnight?
    Charging makes the run cheap for the user, and on one platform charging also lifts the usage-based limits on background jobs (except in its most restricted tier). But a user who never charges at night would never be imported, so the design pairs it with a fallback: if the last successful import is older than, say, 36 hours (our assumption), reschedule with only a network constraint, and always refresh in the foreground on open.
  • How would you find out in the field how late imports actually run?
    Record the requested earliest start, the actual start, the outcome and whether a constraint stopped the run, and report the age of the last successful import each time the app opens. The distribution of that age per platform shows how often users meet stale data, which is the number the design is really judged on.

  • Scheduling the import for 2 a.m. means it runs at 2 a.m.
  • An exact-time alarm is the right tool for a nightly data import.
  • Once a job is scheduled, the home screen can skip refreshing on open.
  • Background work runs whenever the app is not on screen.
  • Constraints only decide whether the job runs, never how late it runs.
open as a page

In a phone photo-editing app, how long does each frame have at 60 Hz and 120 Hz, and what happens when the app misses it?

level: juniorimportance: must knowfreq 58%

basics

~20 s

About 16.7 ms at 60 Hz and 8.3 ms at 120 Hz, of which the app's own work gets only part. A missed deadline is not a slightly late frame: the old picture stays a whole refresh longer.

open as a page

In a phone weather app fetching a 2 KB forecast every 20 seconds, why does the battery drain far more than the bytes suggest?

level: juniorimportance: must knowfreq 48%

basics

~20 s

Each request wakes the cellular radio, which then lingers in high-power states for seconds after the transfer. A request every 20 seconds keeps it from ever reaching standby, so the energy goes on wake-ups and tails, not bytes.

open as a page

In a music-streaming phone app, what do cold, warm and hot starts each rebuild, and why budget the cold start?

level: juniorimportance: must knowfreq 62%

basics

~20 s

A cold start creates the process, builds the app's object graph and draws the first screen; a warm start redoes part of that; a hot start brings a still-resident app forward. Budget the cold start, because it does all the work.

open as a page

A budgeting phone app requests a 15-minute balance refresh, but field logs show a few runs a day; why, and how should the design cope?

level: middleimportance: must knowfreq 58%

basics

~20 s

A periodic interval is a minimum gap, not a timetable; runs also wait for constraints, deep-idle windows, battery-saving modes and usage priority. Design for a few runs a day: refresh on open, show data age, alert from the server.

open as a page

Why does the OS end a phone photo editor while its user is in the camera, and how should the editor avoid losing the edit?

level: middleimportance: must knowfreq 55%

basics

~20 s

The camera creates memory pressure, and the OS reclaims background apps first, a large editor early, without running its code. Save each edit's operations as it commits, and drop rebuildable pixels when leaving the screen.

open as a page

In a phone photo-editing app, a live filter preview drops frames while a slider drags over a 48-megapixel photo; how should the preview be designed?

level: middleimportance: must knowfreq 54%

basics

~20 s

Preview from a screen-sized proxy, not the 48-megapixel original, rendered off the main thread with only the newest slider value; the main thread just swaps in finished images, and the full-resolution render runs after release.

open as a page

In a weather app that sends logs, analytics, forecast refreshes and radar tiles separately, how would you group them so one radio wake-up serves many?

level: middleimportance: must knowfreq 45%

basics

~20 s

Split traffic into what the user is waiting for and what can wait. Send the first at once and flush the deferrable queue in that same burst; a send-by deadline makes a quiet app send one batched burst.

open as a page

A music-streaming app sets up eight third-party SDKs before its first frame; how would you stage their start-up, and which must start first?

level: middleimportance: must knowfreq 58%

basics

~20 s

Give each SDK the latest phase that still works: crash reporting before anything else; analytics, ads and attribution after the first frame; payments, support chat and casting on first use, each behind a seam built on first call.

open as a page

A music-streaming app's cold start crept from 1.2 to 3 seconds over a year of releases; how do you find what sits on its critical path, and what do you cut?

level: seniorimportance: must knowfreq 55%

basics

~20 s

Find the release and device class in field data, trace a cold start on a low-end phone, list everything before the first frame and before playable content, then defer, lazily build or move off the main thread whatever neither needs.

open as a page

In a budgeting phone app, which work should run as urgent and which deferred: a just-saved cash expense, the category-model refresh, the database backup?

level: middleimportance: should knowfreq 48%

basics

~20 s

Only the cash expense is urgent: the user just did it and it is tiny, so it leaves at the first connection. The model refresh and backup are deferrable bulk work that waits for cheap conditions, sparing the small urgent-time ration.

open as a page

In a personal-budgeting phone app, the overnight job that imports transactions and retrains the on-device category model is often stopped partway; how should it be built to finish across runs?

level: seniorimportance: should knowfreq 50%

basics

~20 s

Each wake lasts seconds to minutes and can end without warning, so split the job into small idempotent steps, commit a checkpoint with each step's data, stop between steps, and swap the retrained model in only when complete.

open as a page

Users of a personal-budgeting phone app who open it only on payday, or force-quit it, find imports and backups weeks stale; why, and how should the app catch up?

level: seniorimportance: should knowfreq 46%

basics

~20 s

The OS rations background time by use, so rarely opened apps get few runs, and a force-quit may halt scheduled work until the next open. Record each duty's last success and catch up, in priority order, when the app opens.

open as a page

On a 3 GB phone, how would you budget memory for a photo-editing session with layered edits and a 30-step undo history on a 48-megapixel photo?

level: seniorimportance: should knowfreq 48%

basics

~10 s

Count decoded pixels: a 48-megapixel image at four bytes a pixel is about 192 MB. Hold one full-resolution buffer at most, layers as parameters, screen-sized previews, a tiled export, and undo as operations.

open as a page

In a phone photo-editing app, memory grows about 200 MB each time the editor screen opens and closes until the OS ends it; what keeps a closed screen alive, and how do you tell a leak from a cache?

level: seniorimportance: should knowfreq 50%

basics

~20 s

Something long-lived still references the closed screen: a listener never removed, a task or timer that captured it, a singleton or static map holding it. A cache plateaus at its bound; a leak climbs every open-close cycle.

open as a page

In a phone photo-editing app, why can an average frame rate of 58 fps hide the jank users report after a release, and what should the app measure instead?

level: seniorimportance: should knowfreq 46%

basics

~10 s

An average dilutes a few long stalls among thousands of on-time frames. Measure, during motion only, the share of frames that missed this device's deadline and any frame long enough to look frozen.

open as a page

In a weather app used on rural cellular, hotel Wi-Fi and roaming data plans, how would you decide whether to prefetch the animated rain-radar loop?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Prefetch when the expected gain, the chance the loop is opened times the wait it saves, beats the expected cost: its bytes at this network's price plus any extra wake-up. On unmetered Wi-Fi it usually pays; on roaming it rarely does.

open as a page

In a music-streaming app, how should launch time be measured from real installs, and how does that number become a budget that blocks a regressing release?

level: seniorimportance: should knowfreq 48%

basics

~20 s

Record each launch's start type, entry point, device class, first-frame and usable-content times from real installs; report percentiles per release and segment; fail the release when a segment exceeds its budget or regresses past a set margin.

open as a page

In a music-streaming app, why can launches run slower right after an update, and what does a shipped startup-path profile change?

level: middleimportance: nice to knowfreq 38%

basics

~20 s

Where the runtime compiles app code on the device, updated code runs interpreted or compiled on the fly until the device optimises it later; a shipped startup-path profile lets that code be compiled ahead of time at install.

open as a page

In a weather app on weak rural cellular, when does compressing forecast responses, radar frames and uploaded log batches actually pay on the phone?

level: seniorimportance: nice to knowfreq 35%

basics

~20 s

Compression pays on large, repetitive payloads like forecast JSON and log batches, saving data and full-power radio time on slow links. Tiny responses gain almost nothing, since their cost is wake-up and tail, and recompressing compressed images mostly wastes processor time.

open as a page