skip to content

Why can't a mobile auction app keep its bidding-room connection open while backgrounded, and what replaces it?

level: juniorimportance: must knowfreq 60%

answer

  1. the OS guards the battery
  2. suspended apps run no code
  3. one shared connection for every app
  4. a push prompts, it isn't the record
  5. re-fetch on return to the foreground

basics

~20 s

To save battery the OS soon stops a backgrounded app from running or using the network, so its socket dies. Alerts go through the platform push service instead, and on return the app re-fetches the lot before trusting anything.

solid answer

~40 s

Phones guard their battery hard. On one platform a backgrounded app is soon suspended and runs no code; on the other, an idle device cuts apps off from the network and defers their work - either way a socket held in the background is dead or soon will be, and both platforms discourage keeping an app busy just to stay connected. So the app closes the room's connection when it leaves the screen, and the server sends the outbid alert through the platform push service, which keeps one connection shared by every app on the phone. Push is best effort, so when the bidder returns the app shows the cached lot as possibly stale, fetches the current price and their bid status, and reopens the stream.

go deeper

for a junior

Recall that the OS stops a backgrounded app from running or using the network, so its socket dies, and that push is how a closed app hears news.

for a middle

Explain why push is cheap for the battery - one shared connection for every app - and what the app does on return: show stale, fetch, reopen the stream.

for a senior

Show that correctness never rests on the push: a lost or delayed alert only delays the bidder, because the foreground always re-fetches the server's state.

for a principal

Frame the app-wide rule: no feature may depend on a background connection, every live screen reopens and re-fetches on return, and push is reserved for what must reach a closed app.

## What the OS does to a backgrounded app A phone's battery is the OS's to protect, and the surest way to protect it is to stop apps doing work nobody is looking at. The details differ between the two major mobile platforms, but the design consequence is the same: - On one platform, an app that leaves the screen moves to the background and shortly afterwards to a **suspended** state in which it runs no code at all; the system can reclaim its resources at any time after that. - On the other, a device left unplugged and still with its screen off enters a low-power idle mode in which apps lose **network access** and their jobs and syncs are **deferred** to brief maintenance windows, which come less often the longer the device stays idle. Apps the user has not used recently have their background network activity deferred as well. - Both platforms' guidance discourages keeping an app artificially busy just so the system does not treat it as idle. The exceptions are narrow - tasks the user can see and expects to continue, such as music playback - and an auction room is not one of them. How quickly each of these happens depends on the platform, the device and the conditions, so a design must not assume any fixed grace period. ## Why the socket cannot survive it A **WebSocket** or a held stream is alive only while both ends can send and receive. A suspended app cannot read from its connection or answer a ping; an app without network access cannot send anything. The server sees silence, middleboxes on the path eventually drop the idle connection, and it is dead - often without either side having been told. Even if a socket happened to survive a short trip to the background, the design cannot count on it. So the app does the honest thing: it **closes** the room's connection when the screen goes, and opens a fresh one when it returns. A deliberate close has a second benefit: the server learns at once that this device is no longer watching the room, so it knows the next outbid must go by push rather than assuming the bidder saw it on screen. A connection that silently dies tells the server nothing until its own timeouts expire, and an alert can fall into that gap. ## Push is the background path To reach a bidder whose app is in the background or not running, the server sends the outbid alert through the **platform push service**. The phone already holds one connection to that service, shared by every app on the device, so the alert costs the auction app no connection and no keepalive traffic of its own. Consolidating many apps' events into one session is exactly how push avoids the radio waste that separate per-app connections would cause. Push has limits of its own - delivery is best effort, and messages can be delayed, collapsed or dropped; what a push may carry and promise is a separate topic. So the design treats a push as a **prompt** for the bidder to look, never as the record of what happened. ## Back in the foreground: fetch the truth When the bidder returns, whether by tapping the alert or by opening the app later: 1. Show the cached lot immediately, clearly marked as possibly out of date. 2. **Fetch** the lot's current price, end time and the bidder's own status (leading, outbid, won) from the server. 3. Reopen the room's live stream, resuming after the state just fetched. 4. Replace the cached view with the fetched state, and never let an older push overwrite newer data. ## The app's states at a glance | App state | What carries updates | What the bidder sees | |---|---|---| | Room on screen | the live stream or socket | prices as they change | | Backgrounded or closed | the platform push service, best effort | an outbid alert, if it arrives | | Returning to the room | a fetch, then the stream reopens | a stale view briefly, then the truth | ## Mistakes interviewers listen for - Assuming the socket survives for as long as the process does. - Planning a background timer to poll for outbid status. - Treating pushes as the complete, ordered record of the auction. - Showing the pre-background price as current on return.

  • Why not ask the OS for extra background time and keep the socket a little longer?
    Any extra time an OS grants a backgrounded app is limited and meant for finishing work, such as saving state or completing a request, not for listening. When it ends the app is suspended or cut off anyway, and the time spent holding a socket is battery the user did not agree to spend. Close cleanly and let push cover the gap.
  • The outbid push never arrives. What does the bidder see?
    Nothing until they open the app - which is why correctness must not depend on the push. On return to the foreground the lot screen and the watch list fetch current state, so the bidder learns they were outbid as soon as they look. Push only shortens the time until they look; the server's record is the truth.

A hotel front desk takes calls for every guest, so nobody has to sit awake by the phone; the desk slips a note under your door. The note says someone called, but you still ring back to hear what is true now.

  • The socket stays open as long as the app's process is alive.
  • A backgrounded app can poll for outbid alerts on a timer.
  • A push notification guarantees the bidder learns they were outbid.
  • The last price received before backgrounding is still current on return.
  • Pinging often enough keeps a backgrounded app's socket alive.