High-Traffic Endpoints in February

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

Problem

An endpoint only counts as high-traffic once it logs 80 or more calls, every call included, within a single month. Reading the api_calls log, how many endpoints were high-traffic in February 2026?

When traffic spikes, some endpoints get buried. How many crossed the line?

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 1 of 1 rows
endpoint_count
3

Worked solution and explanation

What this really is

This is a threshold on groups dressed up as a traffic report. The question never asks for a list of endpoints. It asks how many clear a bar, and the bar belongs to each endpoint's February total, not to any single row of api_calls. Anyone can count endpoints. What separates candidates is counting only the ones whose own volume survives the cut, measured inside the month. Skip the cut and you report 10, three of them with a single call. Skip the month and '/api/v1/search' gets in on its all-time 86.

Step 1: Scope the rows to February 2026

The window is a fact about each call: it happened in February or it did not. That makes it a WHERE condition, applied before anything is counted. strftime('%Y-%m', call_time) = '2026-02' keeps every day and hour of that month and nothing else.

Step 2: Total each endpoint, then apply the bar

GROUP BY endpoint turns the month into one row per endpoint, and HAVING COUNT(*) >= 80 keeps the ones whose total clears the bar. COUNT(*) counts calls, not callers: ten calls from one user are ten calls, and an error response still hit the endpoint.

Step 3: Count the survivors

The inner query is the list of busy endpoints, and the outer COUNT(*) collapses it to the single number asked for. Naming the inner result busy_endpoints makes the two levels read like the sentence they implement.

High-traffic endpoints in February
SELECT COUNT(*) AS endpoint_count
FROM (
    SELECT endpoint
    FROM api_calls
    WHERE strftime('%Y-%m', call_time) = '2026-02'
    GROUP BY endpoint
    HAVING COUNT(*) >= 80
) AS busy_endpoints
Counts every endpoint seen
COUNT(DISTINCT endpoint) over February returns 10. '/api/v1/payments', '/api/v1/users/' and '/api/v2/products/' each logged one call there and still count.
Counts endpoints that cleared 80
Totalling per endpoint first and filtering with HAVING returns 3: '/api/v1/users' (111), '/api/v1/orders' (106) and '/api/v2/products' (101). '/api/v1/search' stops at 61.

Common follow-up questions