skip to content

When is a binary payload worth it over JSON for a travel-booking mobile app's search results on low-end phones?

level: middleimportance: should knowfreq 38%

answer

  1. names repeated in every object
  2. compression narrows the byte gap
  3. parse cost is CPU time
  4. one schema, generated on both ends
  5. readable in a proxy, or not

basics

~20 s

When payloads are large and repetitive, parsing shows up on slow phones, and both ends can share a schema. Compression narrows the byte gap, so binary mostly buys parse time and generated types, at the cost of readable traffic.

solid answer

~50 s

JSON repeats every field name as text in every object and is parsed by tokenising text and converting numbers; a schema-driven binary format such as Protocol Buffers sends a small numeric tag per field, numbers in a variable-length binary form, and decodes into generated classes. General-purpose compression removes much of JSON's repetition on the wire, so the byte gap after compression is often modest; it does not remove the phone's work to decompress and parse text. So binary pays for long, number-heavy search lists parsed on low-end devices, or when the team already shares schema files and generated models. JSON wins when payloads are small, when engineers must read traffic in a debugging proxy, and when the app should not carry a schema runtime. I'd measure parse time on the lowest supported device before switching.

go deeper

for a junior

Recall the core difference: JSON sends field names as readable text in every object, a binary schema format sends small numeric tags and needs the schema to decode.

for a middle

Explain the four costs separately: bytes on the wire, what compression does to them, parse time on the phone, and readability. Give a case where each format wins.

for a senior

Insist on measurement: parse time on the lowest supported device against network wait on real links. Plan the debug path, the app-size cost and how schema evolution reaches old builds.

for a principal

Decide whether one encoding becomes the house default across apps and services, weighing shared schemas and tooling against readability and the cost of running two encodings during migration.

## What actually differs on the wire Both encodings carry the same data; they differ in how much of the structure travels with it. - **JSON** is self-describing text. Every object repeats each field name in quotes, numbers are written as decimal digits, and a reader needs no schema to make sense of it. - **A schema-driven binary format** — Protocol Buffers is the one the truth set documents — sends each field as a small numeric **tag** plus its value. Field numbers 1 through 15 take one byte to encode, integers use a variable-length encoding, and field names never travel. A reader needs the schema to know what tag 7 means; the format itself is lean and cannot detect a message decoded with the wrong definition. ## A worked number: field names versus tags Take a search page of 50 hotels with 20 fields each. If field names average about ten characters, each JSON field spends roughly 13 bytes on its name, its quotes and a colon before the value starts: | Encoding | Overhead per field | 50 rows × 20 fields | |---|---|---| | JSON, uncompressed | about 13 bytes of name and punctuation | about 13,000 bytes | | Binary, low field numbers | 1 byte of tag | about 1,000 bytes | That is the honest headline, and it is also where compression enters. Repeated names are exactly what general-purpose compression is good at, so once the response is compressed in transit most of those 13,000 bytes collapse. The remaining gap depends on the data: number-heavy rows still favour binary, text-heavy rows such as descriptions and reviews barely change, because strings are strings in either format. ## Bytes, parse cost, codegen, debuggability | Concern | JSON | Schema-driven binary | |---|---|---| | Bytes on the wire | larger raw; much closer once compressed | smaller raw; compression gains less | | Parse cost on the phone | decompress, tokenise text, convert numbers, map to models | decompress if used, read tags and binary values into generated classes | | Typed models | hand-written or generated from an API description | generated from the schema, always | | Reading traffic | readable in any debugging proxy | needs the schema to decode | | App size | a JSON parser the app usually has already | the format's runtime plus generated code | | Old builds and new fields | depends on the parser's settings | unknown fields are kept and re-serialised | Two rows deserve care. **Parse cost** is the one compression cannot touch: a low-end phone still turns every byte of text into objects, and on a long list that shows up as time before the first render and as memory churn. Measure it before claiming it. **App size** is real for the binary path; the format offers a lighter runtime that is much smaller than its full library and is meant for constrained platforms such as phones, but it is still code the app ships. ## What compression changes and what it doesn't - It narrows the **byte** difference, often dramatically for repetitive JSON. - It adds its own decompression step on both formats. - It does not reduce the number of fields the phone must parse, so it does nothing for **over-fetching**: trimming fields the screen never draws is a response-shaping fix, not an encoding one. ## When to choose which 1. **Stay on JSON** when payloads are small or text-heavy, when readable traffic matters to the team, and when parse time on the lowest-end supported device is small next to the network wait. 2. **Choose binary** when lists are long and number-heavy, parse time is measurably large on low-end phones, and both ends can share and version one schema. 3. **Choose binary by default** when the protocol already implies it, for example when calls are gRPC with a shared service definition. ## Traps when switching - **Losing readability without a plan.** Keep a debug path: the format defines a JSON mapping, so a debug build can request JSON. Converting to JSON drops unknown fields and follows different safe-change rules, so it is a debugging aid, not a second contract. - **Expecting binary to fix the screen's shape.** A smaller encoding of the wrong fields is still the wrong fields. - **Forgetting old builds.** How new fields and enum values reach years-old builds is the versioning discussion's; binary helps there, but only if the schema is evolved with care.

  • Can a mobile team get binary's benefits while keeping readable traffic for debugging?
    Partly. The binary format defines a JSON mapping, so a debug build or a request header can ask for JSON while release builds use binary. Two cautions: converting to JSON drops unknown fields, and the safe-change rules differ between the two forms. Treat the JSON form as a debugging view, not as a second supported contract.
  • How would you prove that parse cost matters before moving a mobile app to binary payloads?
    Measure on the lowest-end device you support, with real responses: time from the last byte received to models ready, peak memory during parsing, and compressed versus uncompressed sizes. Compare that time with the network wait on your target links. If parsing is a small fraction, switching buys little and costs readability.

  • Binary payloads are always several times smaller than JSON, even after compression.
  • Compressing JSON makes it as cheap to parse as a binary format.
  • A binary format removes the need for a schema shared by both ends.
  • Switching to a binary encoding fixes over-fetching.
  • Any new field the server adds crashes every old build that parses binary.