skip to content

Backend Contract

Shaping the wire contract from the device: protocol and payload choice, app versions that live for years, and the client's request pipeline. Interviewers treat this seam as the backbone of the design.

on this pageshow

explore

questions

21

In a mobile app's design, what are over-fetching and under-fetching for one screen, and why do both cost more on a slow cellular link?

level: juniorimportance: must knowfreq 42%

answer

  1. bytes the screen never draws
  2. round trips the screen waits on
  3. latency, not only bandwidth
  4. dependent calls queue up in sequence
  5. shape the response to the screen

basics

~20 s

Over-fetching downloads fields a screen never shows; under-fetching makes the screen send several requests, often one after another, to build one view. On a slow, high-latency cellular link the first wastes scarce bandwidth and data, the second stacks round trips.

solid answer

~50 s

**Over-fetching** is an endpoint returning far more than the screen draws: a hotel search list that receives full hotel records, with long descriptions and every room type, just to show a name, a price, a rating and a thumbnail. **Under-fetching** is the opposite: one call cannot fill the screen, so the app makes several, and when one call needs an ID from another's answer they run one after another. On a phone both hurt more than on a desktop: cellular round trips are long and variable, bandwidth can be tiny while roaming, data may be metered, and a low-end phone pays CPU time to parse every byte it receives. The fix is to shape the response to the screen, with a screen-shaped endpoint, a field selection or a server-side composer, so one round trip carries what the view needs.

go deeper

for a junior

Recall both definitions with one example each from a screen you know: extra fields versus extra calls. Then say why a slow, high-latency cellular link makes each one expensive.

for a middle

Explain dependent versus independent calls: independent ones overlap on one connection, dependent ones add a round trip each. Put a number on one screen's waste in bytes and in round trips.

for a senior

Show judgment: some over-fetching is a deliberate prefetch, and every way of shaping responses moves cost to the server. Say where you would shape this app's screens and why.

for a principal

Treat response shaping as a contract decision across many screens and years of builds: who owns screen-shaped responses, how they evolve, and when per-screen endpoints sprawl enough to justify a query layer.

## Two opposite mismatches A screen in a mobile app needs a particular set of data to render. The API behind it rarely returns exactly that set, and the mismatch comes in two directions: - **Over-fetching** — the response carries fields the screen never shows. A search-results row needs a hotel's name, price, rating and a thumbnail URL, but the endpoint returns the whole hotel record: the full description, every amenity, every room type and its cancellation terms. - **Under-fetching** — one response is not enough to fill the screen, so the app makes several requests. A hotel detail screen may need the hotel record, its photos, a review summary and live room availability, each from a different endpoint. Under-fetching becomes much worse when calls are **dependent**: the availability call needs the room or rate identifiers that only the hotel call returns, so it cannot start until the first answer arrives. Independent calls can overlap; dependent calls cannot. ## Why a phone pays more than a desktop The same mismatch costs a mobile client more, for several reasons that stack: - **Latency dominates.** A cellular round trip is long and varies widely; on a roaming connection abroad it can take hundreds of milliseconds before the server even starts work. Every dependent call adds at least one full round trip. - **Bandwidth can be tiny.** On a congested or roaming link, throughput can fall to a slow 2G-class rate, so unused kilobytes turn into seconds. - **Data costs money.** Roaming data is often metered, so over-fetched bytes are paid for by the user. - **Parsing costs CPU.** A low-end phone must decompress and parse every byte it receives, including fields it then throws away. - **The radio stays busy.** Each extra exchange keeps the radio in a high-power state longer; the energy model belongs to the device's network budget, but it points the same way. ## A worked number from a travel-booking app Take the scenario's own numbers: a roaming link of about 100 kbit/s (12.5 KB per second) and a round trip of about 400 ms. | Mismatch | What the screen does | Network cost | |---|---|---| | Over-fetching | 30 search results at about 8 KB each = 240 KB | about 19.2 s of transfer | | Shaped list | 30 rows at about 300 bytes each = 9 KB | about 0.7 s of transfer | | Under-fetching | hotel, then rooms, then availability, each waiting for the last | 3 × 400 ms = 1.2 s of waiting alone | | Composed call | one request returns all three parts | about 400 ms of waiting | The numbers ignore handshakes and server time; real links add both. The point stands: on this link the search list is unusable when over-fetched, and the detail screen spends more than a second just waiting on round trips when under-fetched. ## Ways to shape the response to the screen There are three common places to fix the mismatch, and each moves cost somewhere else: 1. **A screen-shaped endpoint** — the API offers a list view and a detail view, or a parameter that selects a sparse set of fields. Simple and cacheable, but every new screen asks the server team for a new shape. 2. **A client-specified query** — a query language such as GraphQL lets the client name exactly the fields one screen needs in one request; the server then pays the cost of resolving arbitrary selections. 3. **A server-side composer** — a backend-for-frontend calls several services inside the data centre, where a hop is cheap, and returns one response sized for the screen. ## Over-fetching is not always a defect Some over-fetching is deliberate. Including a few detail fields in each search row can make the detail screen open instantly when most users tap through, trading extra bytes for a saved round trip. That is a prefetch bet, measured by how often users actually tap and by what the link costs, and the cost model for that bet belongs to the device's network budget. The defect is accidental waste: bytes nobody decided to send. ## What to say in the interview - Name both directions and give one concrete example of each from the app being designed. - Separate dependent calls, which serialise, from independent ones, which can overlap on one connection. - Put a number on it: bytes per list, round trips per screen, on the slowest link the app must support. - Say where you would shape the response, and what that choice costs the server team.

  • Is putting detail-screen fields inside each search result ever the right call for a mobile app?
    Yes, when most users tap through and the extra bytes are small next to the round trip they save. It is a deliberate prefetch, so it should be measured: tap-through rate, the added bytes per page and the link the app usually runs on. If few users open details, the extra fields are just waste on a metered link.
  • Does sending a screen's calls in parallel solve under-fetching on a mobile link?
    Only partly. Independent calls can overlap on one multiplexed connection, so together they cost roughly one round trip. Dependent calls cannot overlap, because the second needs the first's answer. Parallel calls also each carry headers, each need their own failure handling, and the screen must cope with some parts arriving and others failing.

  • Bandwidth is the only network cost; the number of requests does not matter on mobile.
  • Fetching the full object costs nothing extra once the connection is open.
  • Firing dependent calls in parallel removes their sequential round trips.
  • Over-fetching is always a defect, even when it deliberately prefetches the next screen.
  • Compression makes unused fields free, so trimming the response is pointless.
open as a page

In a mobile app with server-driven screens, what does the server send, and what must the installed build already contain?

level: juniorimportance: must knowfreq 32%

basics

~20 s

The server sends data: a tree of typed components with their properties and tap actions. The build must already ship a renderer for each component type and a handler for each action, so the server can recompose only what the build knows.

open as a page

Why must a mobile app's backend stay compatible with app builds released years ago, when a website's backend usually need not?

level: juniorimportance: must knowfreq 45%

basics

~20 s

An installed app build cannot be redeployed: users update late or never, so builds from years ago keep calling the API. The server changes in minutes but adoption takes years, so each change must work for every supported build.

open as a page

Would you choose REST, GraphQL or gRPC for a travel-booking mobile app used on slow roaming networks, argued from the device?

level: middleimportance: must knowfreq 46%

basics

~20 s

Argue from round trips per screen on a slow radio: REST keeps HTTP caching and easy debugging but needs screen-shaped endpoints, GraphQL fetches one screen's fields in one request, and gRPC brings binary messages and codegen but needs HTTP/2 end to end.

open as a page

In a mobile payments app, how do you make the Send money call safe to retry on a flaky network?

level: middleimportance: must knowfreq 55%

basics

~20 s

Create one idempotency key on the device when the user confirms the transfer, send it in the Idempotency-Key header, and reuse that same key on every retry of that intent, automatic or manual. A new key per attempt can pay twice.

open as a page

In a mobile wallet app, five in-flight calls all get 401 when the access token expires; how does the client refresh once and replay them?

level: middleimportance: must knowfreq 60%

basics

~20 s

Route every 401 through one shared refresh gate: the first caller starts the refresh, the rest wait for its result, then each replays once with the new token. A refresh failing with invalid_grant fails them all and signs out.

open as a page

How should a ride-hailing app's server signal a minimum-supported-version gate so that even a badly broken old build still obeys it?

level: middleimportance: must knowfreq 44%

basics

~20 s

The app sends its build version on every request; below a hard floor, any call gets one frozen, distinct block response that the app checks before parsing the body. That contract ships in the first release and never changes.

open as a page

After adding a new fare field beside the old one in a ride-hailing app's API, when may the server stop sending the old field?

level: middleimportance: must knowfreq 42%

basics

~20 s

Only once no supported build reads it: the minimum supported version must sit above the last release whose code reads the old field. Until then the server fills both fields from one source and never changes the old one's meaning.

open as a page

In a server-driven mobile app, what should a two-year-old build do when a layout contains a component type it has never seen, and how does a versioned layout schema help?

level: seniorimportance: must knowfreq 30%

basics

~20 s

Never crash: skip an unknown optional component, draw a server-supplied fallback where one exists, and show the last-good or bundled screen when a required one has neither. A versioned schema lets the server avoid sending such components at all.

open as a page

In a mobile wallet app, why should the request pipeline refresh the access token on a 401 but not on a 403?

level: juniorimportance: should knowfreq 45%

basics

~20 s

A 401 says the credentials themselves were refused, usually an expired access token, so one refresh and one replay can fix it. A 403 says valid credentials lack permission; a refreshed token carries the same rights, so refreshing cannot help.

open as a page

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%

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.

open as a page

In a mobile wallet app's networking layer, in what order should the idempotency-key, retry, auth and logging interceptors run, and why?

level: middleimportance: should knowfreq 35%

basics

~20 s

Outermost the idempotency key, so every attempt shares it; then retry; then auth, so each attempt carries the current token and handles its own 401; innermost logging, so it records each real attempt with secrets redacted.

open as a page

In a server-driven mobile app, when is a layout change the right tool rather than a remote flag, an over-the-air update or a store release?

level: middleimportance: should knowfreq 28%

basics

~20 s

A layout change fits when only the arrangement of components the build already ships changes. A remote flag switches between shipped code paths, an over-the-air update replaces interpreted code where the app has some, and new native components or behaviour need a store release.

open as a page

For a server-driven home screen in an installed app, what renders on an offline first launch and on an offline relaunch?

level: middleimportance: should knowfreq 24%

basics

~20 s

A bundled default layout covers the first launch, and the last layout that parsed and rendered covers every later one. The app draws that copy at once, with cached or placeholder data, and replaces it only with a newer layout that validates.

open as a page

In a travel-booking mobile app, what does a backend-for-frontend composing the hotel detail screen save the device, and what does it cost?

level: seniorimportance: should knowfreq 36%

basics

~20 s

It turns several dependent calls into one radio round trip carrying only the screen's fields, and lets the server change composition without an app release. It costs a service to own, an extra hop, and response shapes old builds pin.

open as a page

In a mobile wallet app, why do the transfer call, the balance read and an avatar prefetch need different timeouts, priorities and deduplication?

level: seniorimportance: should knowfreq 30%

basics

~20 s

Their failure costs differ. The transfer gets a generous deadline and is never deduplicated; the balance read gets a short deadline and shares one in-flight call; the prefetch is short, lowest priority and dropped on failure, so it never delays the user.

open as a page

In a mobile payments app, the user leaves the Send screen while the transfer request is in flight; what should the pipeline cancel, and what must it not?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Cancel the calls that only served the screen, such as recipient search, avatars and the fee quote. Keep the transfer running in a scope that outlives the screen: a sent request cannot be recalled, so resolve its outcome with the same idempotency key.

open as a page

After a server-driven layout change in a mobile app, one customer segment sees a broken promotions section while everyone else is fine; how do you design to find and reproduce it?

level: seniorimportance: should knowfreq 21%

basics

~20 s

Make every layout traceable: an id and revision plus the inputs that composed it, such as segment, schema version and locale. Log client fallbacks against that id, keep composed layouts retrievable, and validate each change per segment and schema version before publishing.

open as a page

A ride-hailing server adds a ride category that two-year-old rider app builds have never seen; what must those old builds and the server each do?

level: seniorimportance: should knowfreq 36%

basics

~20 s

The old build must map the unknown value to an explicit unknown case and hide or generically show it, never crash or guess. The server must not offer the category to builds that cannot book it, judged by version or declared capability.

open as a page

A ride-hailing server team wants to retire an endpoint that some old rider app builds still call; how do you decide when and how to switch it off?

level: seniorimportance: should knowfreq 30%

basics

~20 s

Measure who still calls it by app build, in riders and rides, then either keep a cheap adapter or raise the hard minimum version above the last calling build. Switch it off only after that floor is in force.

open as a page

Over one HTTP/2 connection on a lossy roaming link, what stalls a travel-booking mobile app's hotel screen, and what does HTTP/3 change?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

On HTTP/2 every request shares one TCP connection, so one lost packet stalls all streams until it is retransmitted. HTTP/3 over QUIC blocks only streams whose data was lost, and lets the client migrate the connection when the network changes.

open as a page