Extraneous fetching
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Extraneous fetching: the 60-second story

    Extraneous fetching

    The screen shows 20 orders. The API sends 500, every field.

    Assume 4 KB per order, so 2 MB to show 2 KB. On 4G at 8 Mbit/s, that’s 2 s, not 2 ms.

    1,000×

    more bytes than the screen uses

    At 250 requests a second, 2 MB responses mean about 4 Gbit/s of egress and 2 GB/s of garbage, against 4 Mbit/s and 5 MB/s for one page.

    Is one big response always better?

    Bad: Ship it all

    500 orders to skip one page call is 2 s to save 60 ms.

    Good: Bundle what pays

    Bundle extras under bandwidth × RTT, about 60 KB on 4G.

    SELECT * is a promise about the future

    It means “whatever columns this table has, forever”. Add a 50 KB description_html next year, and every list query silently starts shipping it.

    Detect it: a fast query inside a slow request

    The query takes 45 ms and mapping 500 orders 200 ms, then the phone downloads 2 MB for 2 s. Server dashboards say 245 ms.

    Fetch only what the screen needs

    1. Name columns; never SELECT * on hot paths
    2. Filter, sort, sum and LIMIT in the query
    3. One keyset page through a covering index
    4. Views or field masks that reach the query

    25,000

    requests a minute, up from about 2,000

    In Azure’s test, an endpoint pulled over 280 KB into the app to return a 14-byte total. Summing in SQL cut the read to 53 bytes.

    You add a DynamoDB ProjectionExpression for 5 of 40 attributes. Does the bill drop?

    The catch

    No. Reads are charged on item size, in 4 KB steps. To cut capacity, shrink the item.

    Say it like this

    Decide what the screen needs as early as possible, ideally in the database. Named columns, filter, sort and limit in the query, one page at a time, details on demand.