Cheapest CDN Route

An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.

Domain
SQL
Difficulty
easy
Seniority
L5
Asked in
Meta

Problem

Our SFO edge cache keeps evicting objects, and we suspect it was sized below the heaviest payload it actually delivers. From cdn_logs, find the largest payload in bytes among the status-200 responses that edge served.

The cheapest path across regions.

Tables

cdn_logs

Columns: log_id INTEGER, edge_loc TEXT, req_path TEXT, status INTEGER, bytes INTEGER, cache_hit INTEGER, served_at TEXT

cdn_logs: 10 of 200 rows
log_idedge_locreq_pathstatusbytescache_hitserved_at
537SFO/js/app.min.js200143702026-02-02 01:07:13
574LHR/css/main.css200277402026-03-03 02:14:26
611NRT/images/hero.jpg206411112026-04-04 03:21:39
648SIN/api/v1/data301544802026-05-05 04:28:52
685FRA/fonts/roboto.woff2304NULL02026-06-06 05:35:05
722SYD/video/intro.mp44038122NULL2026-07-07 06:42:18
759GRU/favicon.ico4049459NULL2026-08-08 07:49:31
796IAD/assets/logo.png?v=250010796NULL2026-09-09 08:56:44
833SFO/js/app.min.js 50312133NULL2026-01-10 09:03:57
870LHR/assets/logo.png2001347002026-02-11 10:10:10

Expected output

First 1 of 1 rows
largest_payload
108397

Worked solution and explanation

What this is really asking

This is a scoped scalar extreme wearing a capacity-planning costume. The skill: narrow cdn_logs to one cohort (the SFO edge, successful responses only) and take MAX(bytes) over the survivors. The trap is that a bare MAX(bytes) returns the global heaviest object, a SIN response at 133800, and dropping the status filter lets a SFO 404 at 129789 win. Get either filter wrong and you report the wrong object's size instead of SFO's real 108397.


Break down the requirements

Step 1: Filter the cohort

Two predicates on cdn_logs: LOWER(edge_loc) = 'sfo' matches the SFO edge and defends against casing variants in free-text geo codes, and status = 200 keeps only clean deliveries so an error response's byte count cannot leak in.

Step 2: Aggregate to one number

MAX(bytes) over the filtered set. No GROUP BY, no ORDER BY, no LIMIT. MAX ignores the null bytes rows (the 304 and 206 responses) for free, and the prompt asks for a single value.


The solution

SCALAR MAX WITH TWO FILTERS
SELECT MAX(bytes) AS largest_payload
FROM cdn_logs
WHERE LOWER(edge_loc) = 'sfo'
  AND status = 200

COMMON FOLLOW-UP QUESTIONS

Common follow-up questions