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?
answer
- the OS picks the moment
- constraints, not a clock
- earliest start means not sooner
- late or never are both normal
- show the data's age, refresh on open
basics
~20 sSubmit 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 sA 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
Recall that the OS, not your code, decides when background work runs, and that an earliest start time means "not before", never "exactly at".
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.
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.
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.