Low Throughput Pipelines

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
Spotify

Problem

Every row of data_pipes is a single pipeline run, carrying both the rows it read in and the rows it wrote out. List each run that wrote out fewer than 2000 rows, with its pipeline name and output count, highest count first.

Pipelines barely moving data.

Tables

data_pipes

Columns: pipe_id INTEGER, pipe_name TEXT, status TEXT, rows_in INTEGER, rows_out INTEGER, start_at TEXT, dur_secs INTEGER

data_pipes: 10 of 200 rows
pipe_idpipe_namestatusrows_inrows_outstart_atdur_secs
131etl_usersfailed137972026-02-02 01:00:0028
162etl_eventsrunning2741942026-03-03 02:00:0051
193sync_crmqueued4112912026-04-04 03:00:0074
224agg_dailyskipped5483882026-05-05 04:00:0097
255agg_weeklySuccess6854852026-06-06 05:00:00NULL
286export_s3FAILED8225822026-07-07 06:00:00143
317import_csvsuccessNULL6792026-08-08 07:00:00166
348ml_trainfailed10967762026-09-09 08:00:00189
379dbt_buildrunning1233NULL2026-01-10 09:00:00212
410etl_ordersqueued13709702026-02-11 10:00:00NULL

Expected output

First 5 of 44 rows
pipe_namerows_out
etl_orders1940
etl_orders1940
dbt_build1843
dbt_build1843
import_csv1649

Worked solution and explanation

What this really is

This is a row-level filter in a monitoring costume, and the whole test is the grain. Anyone can write WHERE rows_out < 2000. What separates candidates is noticing that each row of data_pipes is one run, and that the same pipeline shows up again and again, often with the same output count. Reach for GROUP BY or DISTINCT because the ask mentions a pipeline name and a count, and the 44 qualifying runs shrink to 22 lines or fewer. The repeat low-output runs, the exact anomalies being hunted, quietly vanish. The other slip is reading 'rows' as rows_in, which returns a different set of runs entirely.

Step 1: Keep the run as the grain

Nothing in the ask says to summarise a pipeline. 'Each run' means one output line per row of data_pipes, so there is no GROUP BY, no aggregate and no DISTINCT. The two etl_orders runs at 1940 are two separate incidents and both belong in the answer.

Step 2: Filter on rows_out, not rows_in

Low output means what the run wrote out. rows_in sits right next to it and filtering on it looks just as plausible, but it measures the input side and selects different runs. WHERE rows_out < 2000 keeps the runs that actually under-delivered.

Step 3: Sort by output count, highest first

One key does it: ORDER BY rows_out DESC. Runs that share a count, such as the eight runs that logged -1, can come back in any order among themselves. The grade checks the sort, not how the ties fall.

Every low-output run, highest count first
SELECT pipe_name, rows_out
FROM data_pipes
WHERE rows_out < 2000
ORDER BY rows_out DESC
Rolled up
Adding DISTINCT, or GROUP BY pipe_name, rows_out, returns 22 lines, and grouping by pipe_name alone returns one per pipeline. Each repeated run, like dbt_build at 1843 twice, folds into a single line.
One row per run
With no GROUP BY and no DISTINCT, all 44 qualifying runs come back, duplicates included, because two runs with the same count are two things that went wrong.

Common follow-up questions