A preview tier must fit a fixed storage budget across millions of images; how do you choose the quality operating point?
answer
- a budget is a policy, not a setting
- equal marginal gain, not equal bytes
- content decides rate at fixed fidelity
- find the bend on a real sample
- keep the masters lossless
basics
~20 sMeasure the operational curve on a representative sample, then allocate so the quality gained per extra byte is equal across items rather than fixing one setting or one byte target. Decide the distortion measure first, and keep lossless masters.
solid answer
~40 sThere are two naive policies and both are wrong on their own. A **fixed byte target per item** gives a predictable bill and uneven quality, because busy content needs more bits than flat content at the same fidelity. A **fixed quality setting** gives even fidelity and an unpredictable bill, for the same reason read backwards. Under one shared budget the optimal allocation equalises the **marginal quality per byte** across items — minimise `distortion + lambda * bytes` per item and tune the single `lambda` until total bytes hit the budget. Before any of that, pick the distortion measure you actually mean and validate it against viewers on a sample, because squared error and a perceptual measure land on different points. And keep high-fidelity masters, so the decision stays reversible.
code
pseudocode · 17 lines# spend one shared byte budget where it buys the most quality
lambda = initial_guess # price of a byte, in distortion units
repeat:
for each item i in library_sample:
pick[i] = setting s minimizing (dist(i, s) + lambda * bytes(i, s))
total = sum over i of bytes(i, pick[i])
if total > budget:
increase lambda # bytes cost more, so fewer are spent
else if total < budget:
decrease lambda
until total is within tolerance of budget
report lambda, pick # equal marginal gain per byte across itemsgo deeper
Understand the basic tension: a fixed size per item makes the bill predictable and the quality uneven, and a fixed quality setting does the opposite. Neither controls both.
Explain why content-dependence causes that tension — the same fidelity costs more bits on detailed content — and why returns from extra bytes diminish rather than scale.
Measure before deciding: sweep settings on a representative sample, find the bend relative to the budget, cap outliers, and re-measure when the content mix shifts.
Own the two things the curve cannot decide: which distortion measure the organisation optimises, and how much distortion the product is willing to ship — with masters retained so the decision stays reversible.
## Two policies that sound the same and are not | Policy | The bill | The quality | Where it fits | |---|---|---|---| | Fixed bytes per item | Exactly predictable | Uneven — busy content starves | Hard storage or bandwidth caps | | Fixed quality setting | Unpredictable | Even against the chosen measure | Content-heterogeneous libraries | | Equal marginal quality per byte | Hits a total budget | Uneven by design, optimally so | One shared budget across many items | The reason the first two differ is exactly the content-dependence in the rate-distortion trade: at a given fidelity budget, a detailed photograph needs a higher rate than a flat graphic. Fix the bytes and you fix the rate, so fidelity varies. Fix the fidelity and the rate varies. There is no setting that does both. ## What the optimum actually equalises With one total budget spread over many items, the allocation that minimises total distortion equalises the **marginal return**: the distortion you would save by giving any item one more byte should be the same for every item. If one item would gain more per byte than another, move bytes from the second to the first and the total improves — so at the optimum no such move helps. Operationally that is a single-knob search. For each item, choose the setting minimising `distortion + lambda * bytes`; the same `lambda` for every item is what makes the marginal returns equal. Then tune `lambda` alone until total bytes land on the budget. A larger `lambda` prices bytes higher and shrinks the total; a smaller one spends more. The consequence is counter-intuitive and worth saying out loud in a review: **the optimal policy gives different items different quality settings on purpose**. Content where bytes buy little gets fewer of them. ## Running the decision 1. **Decide what distortion means here.** A squared-error target and a structural or viewer-validated target select different operating points. Pick the one you are willing to defend, and never let a decibel figure become the product requirement by default. 2. **Measure the operational curve on a representative sample** — not one image, and not only the easy content. Sweep settings, record bytes and distortion, and look for the bend. 3. **Locate the bend against the budget.** If the budget sits on the flat stretch, cutting it is nearly free. If it sits on the steep part, a ten percent cut is visible and you should be arguing about scope instead. 4. **Solve for the single knob** so total bytes meet the budget, and cap the outliers — a handful of pathological items should not eat the allowance. 5. **Validate with viewers on a sample** before the number becomes policy, then re-measure when the content mix changes. ## The levers that are not the quality setting A storage budget is rarely best met by fidelity alone, and a lead is expected to have looked at the others first: - **How large the previews are.** Halving each linear dimension quarters the sample count, which is usually a far bigger lever than fidelity and is often invisible at the size the artifact is actually displayed. - **How many variants you store.** Every extra stored size or crop multiplies the bill; some of them can be derived on demand and cached with a short lifetime instead. - **Retention.** Cold variants can expire and be regenerated from the master rather than stored forever. - **Store versus recompute.** If regeneration is cheap and access is rare, the budget problem is partly a compute decision wearing a storage costume. ## What the number cannot decide Two guardrails belong in the decision and are not derivable from any curve. First, **keep the masters lossless**. Every conclusion above is reversible only while an undamaged original exists; a library that has deleted its masters cannot re-derive anything later without compounding distortion, and the next format or the next size becomes a second encode over a first encode's damage. The master is what makes the operating point a *choice* rather than a one-way door. Second, **the acceptable fidelity is a product judgement**, not a storage one. What a viewer tolerates in a thumbnail differs from what they tolerate in a full-screen view, and both differ by what the content is for. The curve tells you the exchange rate between bytes and distortion; it does not tell you how much distortion the business is willing to ship. A lead's job in this decision is to make that second question explicit, put a measured exchange rate next to it, and stop the conversation from collapsing into a single quality number nobody validated.
- Why does the optimal policy deliberately give different items different quality settings?Because the exchange rate between bytes and distortion depends on the content. If a flat graphic gains less per byte than a detailed photograph, moving bytes toward the photograph lowers total distortion. At the optimum no such move helps, which means the marginal gain per byte is equal everywhere — and equal marginal gain generally implies unequal settings and unequal sizes.
- The budget is cut by a third. What do you look at before lowering quality?The preview dimensions, the number of stored variants, and retention. Halving each linear dimension quarters the sample count, which usually dwarfs a fidelity change and is invisible at the display size. Dropping rarely used variants and regenerating them on demand from the master converts storage into compute. Fidelity is the lever to move last, and only after re-measuring the bend.
- What breaks if the team deletes the lossless masters after generating previews?The operating point stops being reversible. Any future size, crop or format becomes a second encode over already-damaged input, so distortion compounds and the library's worst copy becomes its source of truth. Retaining masters is what keeps the fidelity decision revisable when the content mix, the display sizes or the budget change.
saying these in an interview costs you the question
- Picks one quality number without measuring the curve.
- Assumes a fixed byte target per item gives uniform quality.
- Treats the storage bill purely as an encoder-tuning problem.
- Deletes the masters once the previews exist.
- Optimises a decibel figure no viewer ever validated.
- Believes halving the budget halves perceived quality.