Highest Latency Endpoints

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

Problem

Surface the 3 endpoints straining the API the hardest by peak latency, listing the worst offender first on down to the mildest, and show each endpoint alongside its maximum latency value.

The slowest endpoints. Everyone notices.

Tables

api_calls

Columns: call_id INTEGER, endpoint TEXT, method TEXT, status INTEGER, latency REAL, user_id INTEGER, call_time TEXT, err_msg TEXT

api_calls: 10 of 670 rows
call_idendpointmethodstatuslatencyuser_idcall_timeerr_msg
8079/api/v1/ordersPOST2004.21002026-02-02 01:07:00NULL
8158/api/v2/productsPUT2007.91972026-03-03 02:14:00NULL
8237/api/v1/searchDELETE20111.62942026-04-04 03:21:00NULL
8316/api/v1/auth/loginPATCH20415.33912026-05-05 04:28:00NULL
8395/api/v1/auth/logoutget30119NULL2026-06-06 05:35:00NULL
8474/api/v2/analyticspost40022.75852026-07-07 06:42:00Not found
8553/api/v1/paymentsGET40126.46822026-08-08 07:49:00Unauthorized
8632/api/v1/users/POST40330.17792026-09-09 08:56:00Rate limit exceeded
8711/api/v2/products/PUT40433.88762026-01-10 09:03:00Internal server error
8790/api/v1/usersDELETE50037.5NULL2026-02-11 10:10:00Bad gateway

Expected output

First 3 of 3 rows
endpointmax_latency
/api/v1/search1713.7
/api/v2/products1696.4
/api/v1/orders1679.1

Worked solution and explanation

Why this problem exists in real interviews

Finding the top 3 endpoints by peak latency tests aggregation with MAX and LIMIT.


Break down the requirements

Step 1: Find max latency per endpoint

GROUP BY endpoint with MAX(latency) gives peak latency per endpoint.

Step 2: Order and limit

ORDER BY max_latency DESC LIMIT 3 returns the top 3.


The solution

Per-endpoint peak latency, top 3
SELECT endpoint, MAX(latency) AS max_latency
FROM api_calls
GROUP BY endpoint
ORDER BY max_latency DESC
LIMIT 3

Common follow-up questions