Rate Limit Rules Per Endpoint

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
Vesta Innovations

Problem

We're documenting the rate-limit configuration for every API endpoint. For each endpoint, surface the smallest and largest allowed values alongside a summary string in the format 'Allowed > X AND Allowed <= Y => Endpoint = /path', so the reference covers every endpoint's range in one place.

Threshold rules, endpoint by endpoint.

Tables

rate_limits

Columns: limit_id INTEGER, client TEXT, endpoint TEXT, allowed INTEGER, blocked INTEGER, window TEXT, checked TEXT

rate_limits: 10 of 200 rows
limit_idclientendpointallowedblockedwindowchecked
129client-002/api/v1/search107NULL5m2026-02-02 01:03:00
158client-003/api/v1/orders114NULL15m2026-03-03 02:06:00
187mobile-app/api/v2/analytics121NULL1h2026-04-04 03:09:00
216partner-api/api/v1/auth128121d2026-05-05 04:12:00
245internal-svc/api/v1/payments135NULL1m2026-06-06 05:15:00
274batch-worker/api/v1/users142NULL5m2026-07-07 06:18:00
303admin-ui/api/v1/search149NULL15m2026-08-08 07:21:00
332webhook-svc/api/v1/orders156241h2026-09-09 08:24:00
361client-010/api/v2/analytics163NULL1d2026-01-10 09:27:00
390client-001/api/v1/auth170NULL1m2026-02-11 10:30:00

Expected output

First 5 of 6 rows
endpointmin_allowedmax_allowedsummary
/api/v1/auth128800Allowed > 128 AND Allowed <= 800 => Endpoint = /api/v1/auth
/api/v1/orders114786Allowed > 114 AND Allowed <= 786 => Endpoint = /api/v1/orders
/api/v1/payments135765Allowed > 135 AND Allowed <= 765 => Endpoint = /api/v1/payments
/api/v1/search107779Allowed > 107 AND Allowed <= 779 => Endpoint = /api/v1/search
/api/v1/users142772Allowed > 142 AND Allowed <= 772 => Endpoint = /api/v1/users

Worked solution and explanation

Why this problem exists in real interviews

This analytics problem uses the rate_limits table to evaluate string concatenation for formatted output. Watch how the endpoint and allowed columns interact in the grouping and filtering logic.


Break down the requirements

Step 1: Group by endpoint

GROUP BY endpoint aggregates all rate limit records per endpoint.

Step 2: Compute min and max allowed

MIN(allowed) and MAX(allowed) give the range.

Step 3: Build the summary string

Concatenate the values into the specified format using || string concatenation.

Step 4: Order by endpoint

ORDER BY endpoint for alphabetical listing.


The solution

Group by endpoint to find rate limit rules per endpoint
SELECT
    endpoint,
    MIN(allowed) AS min_allowed,
    MAX(allowed) AS max_allowed,
    'Allowed > ' || MIN(allowed) || ' AND Allowed <= ' || MAX(allowed) || ' => Endpoint = ' || endpoint AS summary
FROM rate_limits
GROUP BY endpoint

Common follow-up questions