skip to content

For a retail-banking web app's transactions list and detail panel, how would you shape the payloads and page envelope against over- and under-fetching?

level: middleimportance: should knowfreq 54%

answer

  1. fields the screen shows, nothing more
  2. summary row, detail on open
  3. labels inline, no per-row lookups
  4. expand for optional embeds
  5. a total count costs a count query

basics

~20 s

Give list rows a summary representation that already carries the labels they display, fetch the detail when a row opens, and return a page envelope of cursor and has-more, adding a total count only if the screen shows it.

solid answer

~40 s

Over-fetching is a screen receiving fields it never shows; under-fetching is a screen needing more calls than it should. For the transactions list I'd define a summary row (id, date, description, signed amount with currency, category label, pending or booked) and a separate detail representation (merchant, reference, exchange rate) fetched when the panel opens. Rows carry the category label, not just an id, so the list makes no follow-up lookups. If a second screen needs merchant data on rows, an `expand=merchant` parameter adds it without a third representation. The page envelope is `items` plus `nextCursor` and `hasMore`; a total count over thousands of filtered rows means a count query on every page, so I'd include it only if the design actually shows the number.

code

json · 14 lines
json
{
  "items": [
    {
      "id": "tx_8f21",
      "bookedOn": "2026-09-30",
      "description": "Grocery market",
      "amount": { "value": "-42.17", "currency": "EUR" },
      "category": { "id": "groceries", "label": "Groceries" },
      "status": "booked"
    }
  ],
  "page": { "nextCursor": "c_7Hq2Lm", "hasMore": true },
  "appliedFilters": { "from": "2026-09-01", "to": "2026-09-30", "category": "groceries" }
}

go deeper

for a junior

Recall the two terms: over-fetching sends fields a screen never shows; under-fetching makes a screen call again for data it needed.

for a middle

Explain summary versus detail representations, why labels ride on the row, and what an expand parameter adds without a new endpoint.

for a senior

Argue the total count from the screen: what it costs per filtered page, and which cheaper option gives the product the number it actually shows.

for a principal

Decide how many shapes the API maintains: a few named representations are testable and cacheable, while open field selection moves the cost into every combination.

## Two ways a payload fails a screen A payload is the body a screen receives. It can fail the screen in two opposite ways: - **Over-fetching**: the response carries fields the screen never shows. On a transactions list with thousands of rows per account, every unused field is multiplied by the row count: more bytes on a phone network, more parsing on a low-end device, and more server work joining data nobody reads. - **Under-fetching**: the response lacks something the screen needs, so the client must call again. The classic case is a row that carries only a `categoryId` while the list displays the category's name: the client now needs a lookup per distinct category, or a second request, before the list renders properly. Contract design means choosing the shapes so that each screen gets what it renders in as few calls as it reasonably needs. ## Summary and detail representations The list and the detail panel read the same transaction but need different fields: | Field | List row (summary) | Detail panel | |---|---|---| | id, booking date, description | yes | yes | | signed amount and currency | yes | yes | | category label, pending or booked | yes | yes | | merchant name and address | no | yes | | bank reference, exchange rate, original currency | no | yes | | attached statement notes | no | yes | Two named representations, a summary for collections and a detail for one item, keep the list lean and let the panel make one request when the user opens a row. Fetching the detail on open is not under-fetching: it is one request the user asked for, instead of thousands of detail payloads nobody opened. Amounts travel as decimal strings or integer minor units with a currency code, never as binary floating-point numbers, because binary floats cannot represent most decimal fractions exactly. ## Optional embeds: expand versus open field selection When a second screen needs a little more on each row, there are three ways to provide it: 1. **Another named representation.** Clear and testable, but each one is a new contract to maintain. 2. **An include or expand parameter**, such as `expand=merchant`, that embeds a related object when asked. It keeps one representation and adds a small, documented set of optional embeds. 3. **Open field selection**, such as `fields=id,amount,merchant.name`, where every screen lists its columns. Flexible, but every combination is a variant the server must handle and a cache entry the client cannot share with other screens. For a handful of banking screens, named representations plus a small expand list are the simplest contract. Open field selection is what GraphQL does natively; if you find yourself rebuilding it in query parameters, that is a signal to reconsider the style. ## The page envelope, designed with the screen The list reads a page at a time, so its response wraps the rows in an **envelope**: the items plus what the screen needs to ask for more. A minimal one is `items`, `nextCursor` and `hasMore`, plus an echo of the applied filters so the screen can confirm what it is showing. The next-page pointer can instead travel in a `Link` header with `rel="next"` (web linking, RFC 8288); keeping it in the body is simpler for client code that caches the page as one object. A GraphQL API would carry the same information in the cursor-connections convention's `pageInfo`. What the cursor encodes, why it is preferred to an offset on the wire, and how the list consumes the envelope as the user scrolls are neighbouring subjects; here the point is that the envelope is designed together with the screen. ## Is a total count worth its cost? "312 transactions" is cheap to want and expensive to serve: - counting the rows that match a date range and category is work the server repeats on each request, including every next page; - the list's paging control ("load more" or scroll) does not need the total, only `hasMore`; - if the design shows a number, it can come once per filter change: with the first page only, from a small monthly summary read, or as an approximate figure labelled as such. Ask the screen first; add the count only where it is displayed. ## One call per screen, or several? One call per screen is the aim when the screen renders at once. The list and the detail panel are two separate needs in time: the list call on arrival, the detail call on open. Bundling every detail into the list to save that second call is over-fetching dressed up as speed.

  • Product wants the list header to read '312 transactions in September'. How do you deliver it without counting on every page?
    Treat the number as its own small read: return the count with the first page of a filter only, or serve it from a monthly summary request. It is computed once per filter change instead of on every next-page request, and the header can render a moment after the first rows if it arrives later.
  • When is an open field-selection parameter better than named representations?
    When many screens need many different subsets of a wide entity and a named shape for each would never end. The cost is that every combination is a variant the server must handle and a cache entry the client cannot share; with two or three screens, named representations stay simpler.

  • Returning the full detail for every row so the panel opens instantly
  • Sending only category ids and letting each row look up its label
  • Adding a total count to every page in case the list shows it someday
  • Calling a detail fetched when a row opens a case of under-fetching
  • Sending money amounts as binary floating-point numbers in the JSON