Low-Byte CDN Responses

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
L3
Asked in
Salesforce

Problem

Each row of cdn_logs is one response served from an edge location, and the ones under 5000 bytes are the likely truncated or error payloads. List those responses, smallest first.

Tiny responses from the edge.

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 5 of 6 rows
log_idedge_locreq_pathstatusbytescache_hitserved_at
537SFO/js/app.min.js200143702026-02-02 01:07:13
10004201SFO/js/app.min.js200143702022-01-02 01:07:13
574LHR/css/main.css200277402026-03-03 02:14:26
10004202LHR/css/main.css200277402023-02-03 02:14:26
611NRT/images/hero.jpg206411112026-04-04 03:21:39

Worked solution and explanation

What this really is

Strip off the CDN story and this is a filter, a projection and a sort. The interviewer is grading whether your output matches the request row for row. Anyone writes WHERE bytes < 5000. What separates candidates is reading 'smallest first' as ORDER BY bytes ASC instead of the DESC that every top-N question has trained into their fingers, and keeping the 5000 boundary exclusive. Flip the sort and the 1437-byte responses the investigation is hunting end up at the bottom of the list.

Step 1: Keep only responses under 5000 bytes

WHERE bytes < 5000 is strict on purpose: a 5000-byte response is not small enough to flag. The same predicate also handles the rows where bytes is NULL. A comparison against NULL is never true, so the 304s and other unsized responses drop out without a separate IS NOT NULL guard. That is the right outcome, because a size nobody recorded is not a small payload.

Step 2: Name the columns instead of SELECT *

Every field is wanted, so list all seven. The result is the same today, but an explicit list keeps the output stable when someone adds a column to cdn_logs, and it shows the reviewer you know exactly what you are returning.

Step 3: Sort smallest first, and stop there

ORDER BY bytes ASC puts the 1437-byte responses on top. On this data each size appears twice, once for the original and once for a later copy. The request says nothing about which of a tied pair leads, so either order is correct. Do not invent a tiebreaker the question never asked for.

Small responses, smallest first
SELECT log_id, edge_loc, req_path, status, bytes, cache_hit, served_at
FROM cdn_logs
WHERE bytes < 5000
ORDER BY bytes ASC
Largest first
ORDER BY bytes DESC returns the same six rows with the 4111-byte responses on top, so whoever scans the list reads the least suspicious payloads first.
Smallest first
ORDER BY bytes ASC leads with the 1437-byte responses, the ones most likely to be truncated, which is the reason anyone ran the query.

Common follow-up questions