Lowest Latency per Service

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
Asked in
City and County of San Francisco

Problem

For each service in the us-east-1 region, find the lowest latency recorded.

The fastest response each service ever gave.

Tables

svc_health

Columns: check_id INTEGER, svc_name TEXT, status TEXT, latency REAL, uptime REAL, checked TEXT, region TEXT

svc_health: 10 of 200 rows
check_idsvc_namestatuslatencyuptimecheckedregion
137payment-apidegraded3.697.032026-02-02 01:05:00us-west-2
174user-svcunhealthy6.794.062026-03-03 02:10:00eu-west-1
211search-apitimeout9.891.092026-04-04 03:15:00ap-south-1
248gatewayHealthy12.998.122026-05-05 04:20:00eu-central-1
285notif-svcDEGRADED1695.152026-06-06 05:25:00us-east-1
322ml-servinghealthy19.192.182026-07-07 06:30:00us-west-2
359cache-svcdegradedNULL99.212026-08-08 07:35:00eu-west-1
396queue-workerunhealthy25.396.242026-09-09 08:40:00ap-south-1
433cron-svctimeout28.493.272026-01-10 09:45:00eu-central-1
470auth-svcHealthy31.590.32026-02-11 10:50:00us-east-1

Expected output

First 5 of 8 rows
svc_namemin_latency
auth-svc31.5
edge-auth-svc80
event-bus110
feature-flag-svc170
notif-svc16

Worked solution and explanation

Why this problem exists in real interviews

The svc_health table contains svc_name and status values that must be processed with grouping. This appears in mid-level screens to probe whether you reason about the correct aggregation grain before writing any window or GROUP BY clause.


Break down the requirements

Step 1: Filter to the target rows

Apply the WHERE filter to restrict the working set before aggregation. Filtering early reduces the number of rows that downstream operations process.

Step 2: Aggregate with MIN

Group by the output grain and apply MIN() to compute the metric. The GROUP BY must match exactly what the output needs: one row per group key.

Step 3: Order the final output

Apply ORDER BY as specified to produce the expected row sequence. When tied values exist, add a secondary sort column for determinism.


The solution

Filtered MIN with compound ORDER BY
SELECT svc_name, MIN(latency) AS min_latency
FROM svc_health
WHERE region = 'us-east-1'
GROUP BY svc_name

Common follow-up questions