Unmatched Deploy Services

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

Domain
SQL
Difficulty
medium
Seniority
L3

Problem

We expect every service in deploy_logs to have reported at least once to the error tracker in err_tracks, and any that never has is probably shipping without error reporting wired up. The deploy log spells some service names with stray spaces or capital letters, so clean each to one lowercase name and list the silent services alphabetically.

Two registries. They do not agree.

Tables

deploy_logs

Columns: log_id INTEGER, svc_name TEXT, version TEXT, env_name TEXT, status TEXT, deploy_at TEXT, dur_secs INTEGER, author TEXT

deploy_logs: 10 of 200 rows
log_idsvc_nameversionenv_namestatusdeploy_atdur_secsauthor
131payment-apiv1.0.2stagingfailed2026-02-02 01:11:0023bob
162user-svcv1.1.0devrolled_back2026-03-03 02:22:0036charlie
193search-api2.0.0canaryin_progress2026-04-04 03:33:0049dana
224gatewayv2.1.0ProductionSuccess2026-05-05 04:44:0062eve
255notif-svc2.1.1STAGINGFAILED2026-06-06 05:55:0075frank
286analyticsv3.0.0-rc1productionsuccess2026-07-07 06:06:0088Alice
317ml-servingv1.0.3stagingfailed2026-08-08 07:17:00NULLBOB
348auth-svcv1.0.1devRolled_Back2026-09-09 08:28:00114alice
379Payment-APIv1.0.2canaryin_progress2026-01-10 09:39:00127bob
410user-svcv1.1.0ProductionSuccess2026-02-11 10:50:00140charlie

err_tracks

Columns: err_id INTEGER, err_type TEXT, message TEXT, svc_name TEXT, severity TEXT, count INTEGER, first_at TEXT

err_tracks: 10 of 200 rows
err_iderr_typemessagesvc_nameseveritycountfirst_at
137TypeErrorCannot read property of undefinedpayment-apierror82026-02-02 01:11:00
174ConnectionTimeoutConnection timed out after 30suser-svcwarning152026-03-03 02:22:00
211OutOfMemoryHeap space exhaustedsearch-apiinfo222026-04-04 03:33:00
248FileNotFoundFile /tmp/data.csv not foundgatewayFatal292026-05-05 04:44:00
285PermissionDeniedAccess denied for user rootworkerERROR362026-06-06 05:55:00
322RateLimitExceededToo many requests from 10.0.0.1auth-svcfatal432026-07-07 06:06:00
359ParseErrorMalformed JSON in request bodypayment-apierror502026-08-08 07:17:00
396nullpointerexceptionStack overflow in recursive calluser-svcwarning572026-09-09 08:28:00
433TYPEERRORDivision by zerosearch-apiinfo642026-01-10 09:39:00
470NullPointerExceptionUnexpected null value at line 42gatewayFatalNULL2026-02-11 10:50:00

Expected output

First 3 of 3 rows
service_name
analytics
ml-serving
notif-svc

Worked solution and explanation

What this really is

This is a set difference between two registries that never agreed on spelling. Anyone can write "in A but not in B". What separates candidates is checking the left side first: deploy_logs stores 'payment-api' as 'Payment-API', ' payment-api' and 'payment-api ' too. Subtract the raw names and none of those variants match the tracker, so the noisiest service in the fleet shows up on the silent list three times.

Build it in three moves

Step 1: Clean the name, then collapse it

Select LOWER(TRIM(svc_name)) under SELECT DISTINCT and alias it service_name. The cleaning has to happen before the collapse: DISTINCT on the raw column keeps four rows for one service.

Step 2: Subtract what the tracker knows

Filter with WHERE LOWER(TRIM(svc_name)) NOT IN (SELECT svc_name FROM err_tracks). Notice the cleaning is written twice. WHERE runs before the select list exists, so the alias service_name is not available there, and testing the raw svc_name would let 'Payment-API' slip through as silent. The tracker side is already lowercase and unpadded and holds no NULL names, so NOT IN is safe as written.

Step 3: Sort by the cleaned name

Order by service_name, the column you return. Each name appears once, so the order is fully decided.

Deployed services the error tracker has never heard from
SELECT DISTINCT LOWER(TRIM(svc_name)) AS service_name
FROM deploy_logs
WHERE LOWER(TRIM(svc_name)) NOT IN (
    SELECT svc_name FROM err_tracks
)
ORDER BY service_name
Raw names
Six rows: 'analytics', 'ml-serving', 'notif-svc', plus 'Payment-API', ' payment-api' and 'payment-api '. Half the list is one healthy service under three spellings.
Cleaned names
Three rows: 'analytics', 'ml-serving', 'notif-svc'. Every entry is a real service that has never reported an error.

Common follow-up questions