In a fashion catalogue app's photo grid, what should paint before the photos arrive, and what must the product API response carry for it?
answer
- paint from data already fetched
- aspect ratio before pixels
- a colour or a tiny blur
- no extra request per cell
- the grid's copy previews the gallery
basics
~20 sPaint each cell from the product data already fetched: the photo's aspect ratio plus a dominant colour or a tiny encoded blur. In the gallery, show the grid's cached variant first, then swap in the full-screen one.
solid answer
~40 sOn cellular the product list arrives well before its photos, so the cells should paint from that list. Each image object carries its **aspect ratio**, so the layout never jumps, and a **placeholder**: a dominant colour or a short encoded blur of the photo, a few dozen bytes, generated once on the server. A separate tiny thumbnail request per cell defeats the purpose, because each one is another round trip. In the full-screen gallery the app goes **thumbnail-first**: the grid's 640 variant is already cached, so it appears immediately, scaled up, and the screen-size variant replaces it when it arrives. The highest-resolution zoom variant is requested only when the user actually zooms.
go deeper
Remember that the grid paints from the product data first: a correctly sized cell with a colour or blur, then the photo.
Explain which fields the API carries per image, why a separate thumbnail request per cell is wasteful on cellular, and the thumbnail-first sequence in the gallery.
Compare placeholder options by bytes and likeness, defer the zoom variant until zoom, and make the offline and slow-network first second look deliberate.
Make placeholder data part of the shared image contract computed at ingest, so every surface gets it without per-team work or extra requests.
## What the user sees on a weak signal The catalogue app opens a category: the product list (names, prices, image descriptors) is a few kilobytes of JSON and arrives quickly; the forty photos behind it arrive over the next seconds on a weak cellular signal. Without a plan the user sees white rectangles, cells that change height as photos land, and spinners. The fix is to **paint from what has already arrived**. ## What the API response carries for each image | Field | Size (assumed) | What it buys | |---|---|---| | Aspect ratio or pixel dimensions of the original | A few bytes | Cells are laid out at their final size before any pixel arrives, so nothing jumps | | Dominant colour | About 7 characters | A flat tint that matches the photo, so the grid looks intentional | | Encoded blur | A few dozen characters | A soft, recognisable silhouette: a red dress reads as a red dress | | Width list or URL template | Tens of bytes | Lets the app request the right variant | A dominant colour is the cheapest and is enough for many grids. An **encoded blur** is a very low-resolution version of the photo packed into a short string that the app expands into a blurred image locally; it costs a few dozen bytes per image in the JSON and a small amount of CPU on the device. Either is computed **once on the server** when the photo is ingested, not per request. ```json { "id": "p-8812", "image": { "aspect": 0.75, "dominant": "#8a2b2b", "blur": "q8ZtE2m9vXr1kP0aLh3bWc", "template": "https://img.example.com/p/8812/w{width}.{format}", "widths": [320, 480, 640, 960, 1280, 1920] } } ``` With forty products a page, the placeholder data adds roughly one to two kilobytes to the response, small next to a single photo. ## Placeholder options compared - **Nothing or a grey box.** Free, but the grid looks broken on a slow link and gives no hint of the product. - **Dominant colour.** Almost free, paints instantly, a good default. - **Encoded blur.** A few dozen bytes per image, paints instantly, looks like the product. - **A tiny inline thumbnail** (a very small image embedded in the JSON). Better likeness, but hundreds of bytes per image, so the list response grows noticeably. - **A separate small-thumbnail request per cell.** Common, and the wrong default on cellular: each request is another round trip and more radio activity for something that is replaced a moment later. ## Thumbnail-first in the gallery When the user taps a product, the full-screen gallery needs a larger variant, say 1280 pixels wide. The app already holds the grid's 640 variant of the first photo, so the sequence is: 1. Show the cached 640 variant immediately, scaled up to the screen. It is soft but correct. 2. Request the screen-size variant for that photo. 3. Swap it in when it arrives, with a short cross-fade so the change is not a jolt. 4. For the photos the user has not seen in the grid, paint their placeholders from the product data, then load their variants as the user swipes. 5. Request the largest **zoom** variant only when the user starts to zoom into a detail shot, not when the gallery opens. This ordering spends bytes in the order the user needs them, and never makes them stare at an empty screen for a photo the app already has a version of. ## Edge cases worth naming - **A re-shot photo.** The image gets a new content version, so its URL and its placeholder change together; a stale blur over a new photo looks like a bug. - **Cut-out product shots on white.** The dominant colour is the background, so a plain light tint is the honest placeholder; the encoded blur still shows the garment's silhouette. - **A photo whose ratio differs from the cell.** The cell crops to its own ratio, and the placeholder is cropped the same way, so the swap does not shift the picture. ## What stays out of this answer How the image loader decodes, caches and fades placeholders on the device, and how far ahead the gallery prefetches the next photo, belong to the loading pipeline and the list's prefetch policy. What stays here is the **contract**: the server computes placeholder data once, ships it with the product data, and offers the variants the app steps through. A good test in the interview: switch the phone to a poor network and describe the first second of the screen. If the answer is "a grid of correctly shaped, coloured cells", the contract is right.
- Why not request a tiny 32-pixel thumbnail for each cell as the placeholder?Each thumbnail is a separate request, so a grid of forty cells adds forty round trips and radio activity on cellular for images replaced a moment later. Placeholder data in the product response arrives with the list in one request and paints immediately.
- The product list is cached on the device, but the photos are not. What paints when the app opens offline?The cached list still holds each image's aspect ratio and placeholder, so the grid paints its colours or blurs at the right sizes, and photos fill in only for variants the disk cache holds. The screen looks deliberate rather than broken.
A furniture catalogue that prints each item's outline and colour swatch on the page while the full photo is still at the printer: you can already browse, and nothing moves when the photos are pasted in.
- A placeholder needs its own small image request for every cell.
- Cells can be laid out correctly without knowing each photo's aspect ratio.
- The gallery must wait for its full-screen variant before showing anything.
- A blur placeholder can only be made on the device once the photo arrives.
- Fetching the zoom variant upfront costs nothing if the user never zooms.