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?
answer
- a bet with a price
- chance used times time saved
- bytes times this network's price
- ride the burst already paid for
- measure prefetched bytes actually used
basics
~20 sPrefetch 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.
solid answer
~50 sPrefetch is a bet. The **expected benefit** is the chance the user opens the radar soon times the wait it removes; the **expected cost** is the loop's bytes times what a byte costs on this network, plus a wake-up of its own if it does not ride an existing burst, paid whether or not the loop is used. With labelled assumptions (a 1.8 MB loop opened in 30% of sessions) the answer flips with the network: on unmetered Wi-Fi the bytes are nearly free, so prefetch it in the same burst as the forecast; on roaming every unused megabyte is the traveller's money, so load it on demand; on metered home cellular, prefetch the first frames only when rain is forecast and the odds rise. Never prefetch when the user asked the OS to save data, never delay the first screen, and track how many prefetched bytes get used.
code
pseudocode · 9 linesshould_prefetch(item, network, context):
if network.user_saving_data:
return false
p = observed_use_rate(item.kind, context)
benefit = p * item.seconds_saved * seconds_weight
cost = item.bytes * byte_price(network)
if not burst_in_progress():
cost = cost + wakeup_cost
return benefit > costgo deeper
Recall that prefetching trades data and battery now for less waiting later, and that prefetched bytes nobody uses are pure cost to the user.
Explain expected benefit against expected cost, and why riding a burst the app already made is cheaper than a separate prefetch with its own wake-up.
Put labelled numbers in the model, make it conditional on context as well as network, never block the first screen, and close the loop with prefetched bytes used per network class.
Own one cost model that video preload, image sizing and list paging all spend against, with a shared hit-rate metric and a per-session data budget each team's prefetch draws from.
## Prefetching is a bet with a price Prefetching downloads data before anyone asks for it, so it is ready when they do. Done well, it removes a wait and saves a later wake-up; done badly, it spends the user's data allowance and battery on bytes nobody looks at. One platform's guidance says it plainly: prefetching too aggressively risks battery drain, bandwidth and download quota spent on data that is never used. The design question is never "should we prefetch?" but "for this data, on this network, what is the bet worth?" ## The cost model Write the decision as two expected values: - **Expected benefit** = `p_used × time_saved`: the probability the data is used before it goes stale, times the wait it removes (plus, if it would otherwise need its own later transfer, the wake-up that transfer would cost). - **Expected cost** = `bytes × price_per_byte(network) + extra_wakeup`: paid in full every time, used or not. `extra_wakeup` is zero when the prefetch rides a burst the app already made, and a whole wake-up and tail when it does not. Prefetch when the benefit exceeds the cost. Converting seconds of waiting into the same unit as bytes is a product decision, a policy weight the team sets and revisits, not a law of physics. Two inputs move the result most: 1. **`p_used`** comes from the app's own field data: the share of sessions that open the radar, split by context. In a weather app it is strongly conditional, far higher when rain is forecast within the hour. 2. **`price_per_byte`** comes from what the OS reports about the network (metered or not, and whether the user asked to save data), not from the network type. Staleness also decays `p_used`: a radar frame from forty minutes ago is worthless even if the user opens the map, so prefetching it too early wastes it as surely as never opening it. ## The weather app's radar loop, worked Assumptions for this scenario, labelled: a loop of 12 frames at about 150 KB each, about 1.8 MB; the radar opened in 30% of sessions on a dry day and 70% when rain is forecast; four sessions a day. | Network situation | Price of 1.8 MB to the user | Decision | |---|---|---| | Unmetered Wi-Fi | effectively no money; little energy if it rides the forecast burst | prefetch the loop with the forecast fetch | | Metered home cellular, no data-saving request | a slice of a monthly allowance | first frames only when rain is forecast; otherwise on demand | | Metered roaming cellular | the traveller's money, often at a high rate | never speculative; load on demand at reduced quality | | The user asked to save data, any network | the user has said no | no speculative bytes at all | On a metered plan, unconditional prefetching at four sessions a day costs about 1.8 MB × 4 × 30 ≈ 216 MB a month, and on dry days about 70% of that, roughly 150 MB, is never looked at. The same 1.8 MB on unmetered Wi-Fi costs nothing worth arguing about. One platform's guidance offers a rough break-even from its 3G model: for data with a 50% chance of use, about 6 seconds of transfer (roughly 1-2 MB) before the cost of unused data matches the saving, and a cadence of one download every 2 to 5 minutes of 1 to 5 MB. Treat those as one model's figures, not targets; what transfers is the shape of the trade. ## Rules that keep prefetch honest - **Ride the burst.** Prefetch inside a transfer the user already caused; a separate scheduled prefetch pays its own wake-up and tail. - **Never delay the first screen.** Order the burst so the visible forecast arrives and renders first, and the loop streams after it. - **Respect the user's data-saving choice.** It is a statement of intent, not a hint. - **Measure the hit rate.** Report prefetched bytes used divided by prefetched bytes fetched, by network class and context; a falling hit rate means `p_used` is wrong. - **Leave the specifics to their owners.** How many video clips to preload, which image size to request and how far ahead a list loads its next page all spend against this model; deferring a big download until the phone is on Wi-Fi and charging is a job for the OS's deferred-work scheduler. ## What separates answers A middle answer says "prefetch on Wi-Fi, not on cellular". A senior answer writes the model, fills it with labelled numbers, notices that the right decision flips with the forecast as well as with the network, and closes the loop with a measured hit rate.
- Before launch, where does the chance of use come from?From a conservative prior, such as usage of a similar screen or a guess written down as one, and a policy that starts cautious: prefetch only on unmetered networks. Ship it with the hit-rate metric, then loosen it per network and context as the measured share of prefetched bytes actually used comes in.
- The radar is opened far more when rain is near; how does that change the design?Make the decision conditional. When the forecast shows rain within the hour the chance of use rises, so a metered network may justify the first frames; on a dry day the same bytes are mostly waste. The model is evaluated per session with the context in hand, not set once per network type.
- Why not prefetch the radar overnight on Wi-Fi while charging?Because radar is stale within the hour, so a night-time prefetch is wasted by morning. That pattern suits data that stays useful, such as the ten-day forecast or offline map tiles. Scheduling it for unmetered, charging conditions is the OS's deferred-work scheduler's job, and it runs when the OS decides, not at a set time.
- Prefetching is free on any fast connection.
- Network type alone decides prefetch: Wi-Fi yes, cellular no.
- A prefetch nobody uses costs nothing, because the cache absorbs it.
- Prefetching more always helps, since the user never waits.
- Prefetch everything at launch, before showing the forecast, so it's all ready.