# Highest Latency Endpoints

> The slowest endpoints. Everyone notices.

Canonical URL: <https://datadriven.io/problems/highest_latency_endpoints>

Domain: SQL · Difficulty: easy · Seniority: L3

## Problem

Surface the 3 endpoints with the highest peak latency, showing each endpoint and its maximum latency value.

## 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**

```sql
SELECT endpoint, MAX(latency) AS max_latency
FROM api_calls
GROUP BY endpoint
ORDER BY max_latency DESC
LIMIT 3
```

> **Cost Analysis**
>
> Single-pass aggregation. The top-3 sort is cheap.

> **Interviewers Watch For**
>
> The interviewer checks whether you use MAX (peak) vs. AVG (average). The prompt asks for peak.

> **Common Pitfall**
>
> Using AVG instead of MAX smooths outliers. Peak latency requires MAX.

---

## Common follow-up questions

- How would you use p99 instead of MAX? _(Tests PERCENTILE_CONT.)_
- How would you include ties at position 3? _(Tests DENSE_RANK instead of LIMIT.)_
- How would you filter to endpoints with at least 100 calls? _(Tests HAVING COUNT(*) >= 100.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/highest_latency_endpoints)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.