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
| log_id | edge_loc | req_path | status | bytes | cache_hit | served_at |
|---|---|---|---|---|---|---|
| 537 | SFO | /js/app.min.js | 200 | 1437 | 0 | 2026-02-02 01:07:13 |
| 574 | LHR | /css/main.css | 200 | 2774 | 0 | 2026-03-03 02:14:26 |
| 611 | NRT | /images/hero.jpg | 206 | 4111 | 1 | 2026-04-04 03:21:39 |
| 648 | SIN | /api/v1/data | 301 | 5448 | 0 | 2026-05-05 04:28:52 |
| 685 | FRA | /fonts/roboto.woff2 | 304 | NULL | 0 | 2026-06-06 05:35:05 |
| 722 | SYD | /video/intro.mp4 | 403 | 8122 | NULL | 2026-07-07 06:42:18 |
| 759 | GRU | /favicon.ico | 404 | 9459 | NULL | 2026-08-08 07:49:31 |
| 796 | IAD | /assets/logo.png?v=2 | 500 | 10796 | NULL | 2026-09-09 08:56:44 |
| 833 | SFO | /js/app.min.js | 503 | 12133 | NULL | 2026-01-10 09:03:57 |
| 870 | LHR | /assets/logo.png | 200 | 13470 | 0 | 2026-02-11 10:10:10 |
Expected output
| 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
SELECT MAX(bytes) AS largest_payload
FROM cdn_logs
WHERE LOWER(edge_loc) = 'sfo'
AND status = 200COMMON FOLLOW-UP QUESTIONS
Common follow-up questions
- Return the heaviest successful payload for every edge location. (Adds `GROUP BY LOWER(edge_loc)` and lifts the SFO filter; the scalar becomes a per-edge leaderboard.)
- How would partition pruning help, and what predicate would unlock it? (Tests whether you reach for a `served_at >= '2026-08-13'` filter and explain that without it every partition reads.)
- What happens to the null `bytes` rows logged with no body? (`MAX` skips NULLs, so the answer is still defined, but a senior candidate names the assumption and may add `WHERE bytes IS NOT NULL` for clarity.)