skip to content

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%

answer

  1. who is waiting for this byte?
  2. urgent, deferrable, or speculative
  3. ride a wake-up the user caused
  4. a deadline, not a timer
  5. one burst on one reused connection

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.

solid answer

~50 s

Classify every request by who is waiting for it. **Urgent** traffic (the forecast the user just pulled down, the radar frame on screen) goes now. **Deferrable** traffic (log uploads, analytics batches, the next hours' forecast tiles, radar frames not yet shown) waits in an in-app queue with a **send-by deadline**. Whenever the app wakes the radio for urgent work, it drains that queue in the same burst over the same reused connection, so the tail is paid once. If nothing wakes the radio before the earliest deadline, the whole queue goes out as one batch then. With labelled assumptions (about 18 s of radio energy per wake-up), three independent timers making about 190 wake-ups an hour while the app is open collapse to the user's own refreshes plus a few deadline flushes. With no network at all, the app holds the batch rather than making the radio hunt for a signal.

code

pseudocode · 22 lines
pseudocode
enqueue(item):
  if item.urgent:
    send_burst([item], take_all(waiting))
  else:
    waiting.add(item)
    set_alarm(earliest_deadline(waiting))

on_app_foreground():
  send_burst([forecast_request()], take_all(waiting))

on_alarm():
  send_burst([], take_all(waiting))

send_burst(urgent, deferred):
  if not network_available():
    waiting.add_all(deferred)
    report_offline(urgent)
    wait_for_network_then(on_alarm)
    return
  connection = pooled_connection()
  for each item in urgent + deferred:
    connection.send(item)

go deeper

for a junior

Recall that urgent and non-urgent traffic are treated differently: what the user is waiting for goes now, while logs and analytics can wait and go together in one burst.

for a middle

Explain the gate: traffic classes, a send-by deadline per class, draining the queue on every urgent request, and one reused connection per burst. Do the wake-ups-per-hour arithmetic with labelled assumptions.

for a senior

Show the failure modes: everything labelled urgent, deadlines that lose data, SDK timers that bypass the gate. Measure wake-ups per release and draw the line between the in-app gate and the OS's deferred-work scheduler.

for a principal

Make the gate the only door to the radio for app-initiated traffic across teams, with a review for any new recurring wake-up and a per-release wake-up budget that is measured, not assumed.

## Start from who is waiting Every request the app makes is one of three kinds, and the grouping design starts by labelling each one: | Class | Weather-app examples | When it may use the radio | |---|---|---| | **Urgent** | the forecast after a pull-to-refresh, the radar frame now on screen, a search for a town | immediately, because a person is waiting | | **Deferrable** | log uploads, analytics batches, the next hours' forecast tiles, radar frames not yet on screen | on the next wake-up the app makes anyway, or by a deadline | | **Speculative** | the whole radar loop before anyone opens it | only when a prefetch cost model says it pays; a separate decision | The label belongs to the call site and is set by whoever writes it, not guessed later by the networking layer. ## The wake-up gate Inside the running app, deferrable work goes through one small component, call it a wake-up gate, instead of each feature owning a timer: 1. A feature hands the gate an item with a **send-by deadline** (analytics within 15 minutes, next-hour tiles before the hour turns; both are the team's own assumptions). 2. When an urgent request is about to go out, the gate **drains everything waiting** into the same burst, on the same connection. 3. When the app comes to the foreground, the first fetch it makes anyway is the burst everything rides on. 4. If the earliest deadline arrives and nothing has woken the radio, the gate sends **all** waiting items together: one wake-up instead of one per feature. 5. If the OS reports no network, the gate waits for a connection instead of sending. One platform's guidance notes that searching for a cell signal is one of the most power-draining things a phone does, so forcing it on a hiker's weak signal is the worst outcome. Reusing one connection matters inside the burst: a pooled connection skips repeated handshakes, so the burst is shorter and the tail starts sooner. The same guidance names logs and analytics as the textbook case, since non-urgent, app-initiated transfers batch well. ## The arithmetic, with labelled assumptions Assume, as this scenario's figures, about 18 s of radio energy per wake-up (a 1 s transfer, then 5 s of tail at full power and 12 s at low power, from one published 3G example), and these timers while the app is open: - analytics flushed every 30 s: 120 wake-ups an hour; - a log upload every 60 s: 60 an hour; - a forecast refresh every 5 minutes: 12 an hour; - in total about **192 wake-ups an hour**, which at 18 s each adds up to about 3,450 s, nearly the whole hour: the radio barely rests. With the gate, the timed forecast refresh is replaced by a refresh when the app comes to the foreground or the user pulls down, and the only wake-ups the app makes on its own are the deadline flushes: at most 4 an hour if every deferrable class has a 15-minute deadline. Everything else rides what the user causes, which would have happened anyway. The data sent is the same; the radio's busy time falls from nearly the whole hour to a few minutes. ## Where the edges are Grouping changes **when** a request uses the radio, not what the request is: - How long one call waits before giving up, and how it retries, is the request pipeline's rule; the gate only decides which burst a call joins. - Making sure the analytics queue survives a crash and is never counted twice belongs to the event pipeline; the gate only decides when its batch rides. - Work that must happen after the user leaves the app is handed to the OS's deferred-work scheduler, which runs it when the OS decides; the gate covers the time the app is running. - Several sync triggers arriving in one moment and being folded into one pull is a sync-design rule; the gate is the radio-facing layer beneath it. ## What a good answer adds A middle-level answer draws the gate and the deadline. A stronger one names the failure modes: - **Everything labelled urgent**, so the gate never holds anything and the wake-up count is unchanged. - **Deadlines so long** that diagnostic logs from a bad session never leave the phone before it is reinstalled or replaced. - **A third-party SDK with its own timer** that bypasses the gate, which is why the app's transfers per hour must be measured per release, including traffic the team did not write.

  • How do you pick the deadline for each deferrable class?
    From what a late arrival costs. Analytics can wait many minutes; a diagnostic log from a failing session should leave on the next foreground; next-hour forecast tiles must arrive before the hour turns. Set each deadline from that, not from a habit like 30 seconds, and keep them per class so a long one never delays a short one. A long deadline also raises the stakes of losing the queue, which is why the event pipeline persists it.
  • A third-party SDK in the app flushes on its own 60-second timer; what do you do?
    Count it, because its wake-ups drain the same battery. Prefer an SDK option that lengthens or disables its own flush and lets the app trigger uploads, then trigger them from the gate. If it offers neither, measure its transfers per hour and weigh that against its value; an SDK waking the radio sixty times an hour is a design cost, not a detail.
  • Why not hold urgent requests for a second so more traffic can join them?
    Because a person is waiting and the gain is small: the urgent request opens the radio anyway, and deferrable items already join it. Delaying the user's own request trades visible latency for nothing. The one reason an urgent call cannot go at once is no network at all, and then the user should see that state.

  • Every feature should own its own timer so the features stay independent.
  • Sending each analytics event the moment it happens is cheapest because each request is tiny.
  • With no signal, keep trying every few seconds so the data leaves the moment coverage returns.
  • The HTTP client groups requests into one burst on its own, so the app needn't.
  • Batching means holding everything until Wi-Fi, however long that takes.