skip to content

Notification Delivery

The platform push service is the only way to reach an app that isn't running, by visible or data-only messages that are best-effort and throttled. Interviewers probe what push can be trusted to do.

on this pageshow

explore

questions

5

In a parcel-tracking app, why can't a data-only push be trusted to keep the shipments list current, and what does the app do instead?

level: juniorimportance: must knowfreq 62%

answer

  1. the only road into a closed app
  2. a hint, not a delivery
  3. low priority, held, throttled, replaced
  4. a force-quit can discard what was held
  5. fetch the truth whenever the app opens

basics

~20 s

A data-only push is best effort on APNs and FCM alike: it may be held while the phone sleeps, throttled, replaced or lost. Treat it as a hint, and fetch the shipments list whenever the app opens or returns to the foreground.

solid answer

~50 s

For an app that is not running, the platform push service (APNs and FCM) is the only way in, because the OS will not keep the app's own socket alive in the background. A **data-only push**, which shows nothing and only wakes the app, is the weakest kind of message: one service treats it as low priority, may throttle it (its guidance is two or three an hour at most) and discards a held one if the user force-quits the app; the other holds normal-priority messages while the device sleeps. Neither guarantees order, and an accepted send is not a delivered one. So correctness never rests on it. The app refreshes the list on every launch and every return to the foreground, offers pull-to-refresh, and treats each push as a hint that, when it does arrive, makes the list fresh before the user looks.

go deeper

for a junior

Recall that APNs and FCM are the only way to reach a closed app, that a data-only push can be delayed or lost, and that the app fetches its data when it opens.

for a middle

Explain why the services hold, throttle and replace data-only pushes, and show the on-open, foreground and pull-to-refresh paths that keep the list correct without them.

for a senior

Show that every push handler is safe to run zero or several times, that urgent news goes as a visible notification, and that delivery is never inferred from an accepted send.

for a principal

Argue the trade between nudge volume, battery and freshness across features, and set the rule that no feature's correctness may depend on a data-only push arriving.

## Push is the only way into an app that is not running When the user leaves a parcel-tracking app, the operating system soon stops giving it CPU time and network access. It will not keep the app's own socket or polling loop alive for a screen nobody is looking at: on one platform a dozing device has its network access suspended, and on the other a backgrounded app is soon suspended and runs no code at all. The one channel the server can still use is the **platform push service** — APNs and FCM, one per native platform, each run for all the apps on the device. A cross-platform app uses the same two services underneath, so everything below applies to it unchanged. A push comes in two shapes, and they promise very different things: | | Visible notification | Data-only push | |---|---|---| | What the user sees | an alert, a sound or a badge | nothing | | What the app gets | a payload it can read when tapped or opened | a brief wake-up to run some code | | How the services treat it | can go at high priority, sent at once | low priority, held, throttled | | Fits | "your driver is two stops away" | "the shipments list changed" | ## What a data-only push actually promises Very little, and both services say so in their own documentation: - **Best effort, in no fixed order.** Both describe delivery as best effort, and neither guarantees that messages arrive in the order the server sent them. - **Low priority and throttled.** One service treats these background updates as low priority, does not guarantee delivery, and throttles them when there are too many; its guidance is not to send more than two or three an hour. - **Held while the device sleeps.** On the other, a normal-priority message waits while the device is in its deep idle state and arrives when the device wakes. - **Only the newest is held.** On one platform, a phone holding a data-only push drops it when a newer one arrives. - **A force-quit can discard it.** On one platform, if the user force-quits the app, the held data-only push is thrown away. - **Accepted is not delivered.** A success response to the server's send means the push service accepted the message, not that it reached the phone. None of this is a defect to work around with cleverness. The services are protecting the battery and the data plan of a device that runs dozens of apps, and they make the same trade for everyone. ## Designing so correctness never rests on it The rule is simple to state: **a data-only push may make the app fresher, but it must never be the reason the app is correct.** In practice: 1. **Fetch on launch and on every return to the foreground.** This is the guaranteed path. Whatever pushes were lost, the list the user sees after opening the app is current within one network round trip. 2. **Offer pull-to-refresh.** A user who doubts the screen can force the same fetch. 3. **Treat each data-only push as a hint.** When one arrives, start the same refresh the app would run on open. The push says "something changed"; it is not the record of what changed. 4. **Make handling it harmless to repeat or to miss.** Zero, one or three nudges for the same change must leave the list in the same end state. 5. **Use a visible notification for anything the user must know now.** A data-only push cannot alert anyone; "your parcel needs a signature" goes as a visible notification that the system shows even if the app never runs. ## What the user sees meanwhile - The cached list appears at once, with a quiet "updated 2 h ago" line rather than a spinner over a blank screen. - A small refreshing indicator runs while the on-open fetch is in flight, and the line updates when it lands. - If the fetch fails, the cached list stays, labelled as possibly out of date, with a retry. The user never learns whether a push arrived; they only notice whether the list is right, and the on-open fetch is what makes it right. ## Where this question stops Whether a change should carry the new data or only a "something changed" signal is the caching design's question. What the refresh then asks the server for, and how a push, a reconnect and an app foreground arriving together become one request, belong to the sync design. How long the app may run after a push wakes it is the background-work budget's subject. This question keeps the promise itself: push can wake the app sometimes, and correctness never depends on it.

  • If data-only pushes are this unreliable, why send them at all?
    Because they usually do arrive, and when they do the list is already fresh before the user opens the app, which saves a visible loading moment. They are cheap for the server and, kept to a few an hour, cheap for the battery. The design only forbids depending on them: the on-open fetch still runs whether or not a nudge came.
  • Could a scheduled background refresh replace the push nudge?
    It can complement it, but it promises no better. The OS decides when deferred background work runs and may postpone it for hours on an idle phone, so it is another best-effort path. The background-work rules own its details; the guaranteed path is still the fetch when the user opens the app.
  • What should the app do when the user must hear about a change even though the app is closed?
    Send a visible notification. The system shows it without the app having to run, and it can go at high priority so a sleeping phone is woken for it. A data-only push cannot alert the user at all, so it is the wrong tool for 'your parcel needs a signature'.

  • A data-only push always arrives; at worst it is a little late.
  • The app can keep its own socket open in the background instead of using push.
  • Sending data-only pushes at high priority makes them reliable.
  • If the push carries the new status, the app never needs to fetch on open.
  • Pushes reach the phone in the order the server sent them.
  • A success response from the push service means the phone received it.
open as a page

In a parcel-tracking app, how should collapse identifiers and time-to-live be set so a 'driver is two stops away' alert never arrives hours late?

level: middleimportance: must knowfreq 55%

basics

~20 s

Give each alert a time-to-live as long as it stays true (minutes for 'driver nearby') and each shipment one collapse identifier, so newer news replaces older. The push carries an id and version; the app fetches the record.

open as a page

In a parcel-tracking app, how should the push device token be managed so that after one user signs out, the next person on the phone does not get their alerts?

level: seniorimportance: must knowfreq 52%

basics

~20 s

A device token addresses this app on this device, not a person; the server's token-to-account binding decides who gets alerts. Fetch the token each launch, register it with the account and an install id, and detach it at sign-out.

open as a page

In a parcel-tracking app, when should the app ask for notification permission, and what should it still do for a user who refuses?

level: middleimportance: should knowfreq 46%

basics

~20 s

Ask in context, just after the user tracks a first parcel and can see what alerts are for, not at first launch. If they refuse, show shipment news in the app when it opens, offer a settings path, and never nag.

open as a page

In a parcel-tracking app sending high-priority data-only pushes for every list change, 'driver nearby' alerts start arriving late; why, and how should priorities be set?

level: seniorimportance: should knowfreq 42%

basics

~20 s

High priority is for pushes that end in something the user sees. One service demotes an app whose high-priority pushes rarely do, so its real alerts then wait while the phone sleeps. Send only visible, urgent alerts high.

open as a page