skip to content

In a weather app on weak rural cellular, when does compressing forecast responses, radar frames and uploaded log batches actually pay on the phone?

level: seniorimportance: nice to knowfreq 35%

answer

  1. processor time traded for bytes
  2. the tail does not shrink
  3. repetitive text compresses, images don't
  4. the plan saves more than the battery
  5. the server must accept compressed uploads

basics

~20 s

Compression pays on large, repetitive payloads like forecast JSON and log batches, saving data and full-power radio time on slow links. Tiny responses gain almost nothing, since their cost is wake-up and tail, and recompressing compressed images mostly wastes processor time.

solid answer

~50 s

Compression trades processor time for bytes. On a phone, fewer bytes mean less of the user's data allowance and less time at full radio power on a slow link, but they do not shorten the wake-up or the tail. So it pays on **large, repetitive text**, such as a ten-day forecast JSON or a batch of log lines, where it can cut the bytes several-fold. It does almost nothing for a **tiny response** like 'no new warnings', whose energy is nearly all wake-up and tail, and it is wasted on **already-compressed media** such as radar frames in a compressed image format, where a second pass saves little and still costs processor time. For uploads the phone pays the compression cost, so compress large batches only, and only to a server that accepts that coding on requests; otherwise it may refuse the body with `415`.

go deeper

for a junior

Recall that compression trades processor time for fewer bytes, that text compresses well and already-compressed images do not, and that fewer bytes mainly saves the user's data.

for a middle

Explain why the wake-up and the tail do not shrink with the payload, so compression helps large responses on slow links and does nothing for tiny ones.

for a senior

Decide payload by payload with labelled arithmetic: compress forecast JSON and log batches, leave status calls and compressed media alone, and agree request compression in the server's contract.

for a principal

Set a team-wide rule that each new payload justifies its bytes and its wake-ups separately, so compression is never offered as the fix for a request that should not be made at all.

## What compression trades on a phone Compression spends processor time on both ends to send fewer bytes. On a server the trade is usually about bandwidth bills; on a phone it touches three budgets at once: - **The data plan**: fewer bytes means less of a metered allowance or roaming charge. This saving is proportional to the bytes removed. - **Radio energy**: fewer bytes means less time at full power *during the transfer*, which matters on a slow rural link. It does **not** shorten the wake-up or the tail that follows, which are fixed per transfer. - **The phone's processor**: decompressing a response, and compressing an upload, costs processor time and energy on a device that runs on a battery. So the honest question is not "is compression good?" but "for this payload, how many bytes does it remove, and how big is that against the fixed cost of a wake-up?" ## Payload by payload in the weather app | Payload (sizes are this scenario's assumptions) | Compresses well? | Verdict | |---|---|---| | Ten-day forecast JSON, about 60 KB | yes: repetitive keys and numbers | compress the response | | "No new warnings" check, under 1 KB | a little, but the bytes were never the cost | irrelevant; cut the number of these calls instead | | Radar frame in a compressed image format, about 150 KB | barely: the format is already compressed | do not add a second coding | | Uploaded log batch, about 200 KB of text | yes | compress, if the server accepts it | The HTTP specification treats already-compressed formats as a special case: when a media type has an inherent encoding, such as a format that is always compressed, that encoding is not restated as a content coding, and one would be listed only if applied a second time, which is rarely worth doing. ## The arithmetic, with labelled assumptions Assume a rural link delivering about 20 KB/s, a forecast JSON that shrinks from 60 KB to 12 KB, and the radio tail used elsewhere in this design: about 17 s after each transfer (5 s at full power, then 12 s at low power, from one published 3G example). 1. **Uncompressed:** about 3 s of transfer plus about 17 s of tail, so about 20 s of radio activity and 60 KB of the allowance. 2. **Compressed:** about 0.6 s of transfer plus the same 17 s, so about 17.6 s and 12 KB. 3. **Result:** the radio's busy time falls by about 12% (its energy by somewhat more, since the seconds saved were all at full power), while the data used falls by 80%. The lesson generalises: on a phone, compression is mainly a **data-plan and slow-link** optimisation; the battery lever is still the number of wake-ups. On a fast link the transfer-time saving shrinks further, and on a tiny response it disappears. ## Uploads are different Responses are compressed by the server and only decompressed on the phone. Uploads put the compression work on the phone: - Compress **large, text-heavy** request bodies, such as log and analytics batches, where the saving is many kilobytes. - Skip it for small requests and for already-compressed photos or media. - Agree it with the server first. A server that does not accept a content coding on requests may reject the body with `415 Unsupported Media Type`, so the client should know from the API contract that the server accepts it, not discover it by trial on every call. ## Where the edges are - How client and server agree a coding (`Accept-Encoding`, `Content-Encoding`, gzip against newer codecs) is HTTP negotiation and belongs to the protocol layer. - Whether the forecast should be JSON or a binary format, and whether a screen over-fetches, are API-design choices; both change the bytes before compression ever sees them. - This design keeps the phone-side judgment: which payloads deserve compression, and what it can and cannot save on a radio whose fixed cost dominates small transfers. ## What a strong answer says A senior answer refuses the blanket rule in both directions. It compresses big repetitive text, leaves small calls and compressed media alone, does the arithmetic to show that compression mostly saves the user's data rather than the battery, and puts the bigger battery win where it belongs: sending fewer, grouped requests.

  • Would a stronger compression setting for the forecast JSON be worth it?
    Usually it is a server-side choice. If the server compresses the forecast once and serves it to many phones, a slower, stronger setting costs the server once and saves every phone bytes; the phone only decodes. For uploads the phone pays the compression cost, so a fast, moderate setting is the usual choice. Measure decode time on a low-end phone before assuming either way.
  • Why not compress the radar frames again before sending them?
    They are already in a compressed image format, so a general-purpose coding finds little left to remove and can even add a few bytes, while both ends still spend processor time. To send fewer radar bytes, change the frames themselves (smaller tiles, fewer frames, lower quality on slow or metered links), which is the image pipeline's decision.

  • Compression always saves battery because the radio sends fewer bytes.
  • Compressing images again with a general-purpose coding makes them much smaller.
  • Decompressing on a phone always costs more energy than the radio time it saves.
  • Compressing a 1 KB status response noticeably cuts its battery cost.
  • Any server decodes a compressed upload body without it being agreed first.