# Region With Best Uptime

> The single most reliable region.

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

Domain: SQL · Difficulty: medium · Seniority: L3

## Problem

The SRE team is choosing which region to use as the gold standard for uptime SLAs. Which region has the highest average service uptime, and what is that average?

## Worked solution and explanation

### Why this problem exists in real interviews

This tests whether a candidate can demonstrate retrieving a bounded result set. This pattern appears frequently in mid-level SQL rounds where interviewers want to see structured thinking.

---

### Break down the requirements

#### Step 1: Aggregate by `region`

`GROUP BY region` collapses rows to one per group. The aggregate functions (`SUM`, `COUNT`, `AVG`, etc.) compute the metric for each group.

#### Step 2: Order and limit the output

`ORDER BY` with `LIMIT` returns only the top result. The sort must be deterministic; add a tiebreaker column if needed.

---

### The solution

**Grouped aggregation with ordering**

```sql
SELECT region, AVG(uptime) AS avg_uptime
FROM svc_health
GROUP BY region
ORDER BY avg_uptime DESC
LIMIT 1
```

> **Cost Analysis**
>
> With ~25M rows, the GROUP BY reduces the working set before any downstream operations. An index on the filter/join columns would reduce the scan to a seek.

> **Interviewers Watch For**
>
> Interviewers watch for whether the query returns exactly the columns and ordering the prompt specifies; how quickly you identify the core operation and write clean, minimal code.

> **Common Pitfall**
>
> Using LIMIT without ORDER BY returns an arbitrary subset. Always pair LIMIT with a deterministic ORDER BY.

---

## Common follow-up questions

- What if the data volume grew 10x? _(Tests whether the candidate thinks about scan cost, indexing, and materialized views.)_
- How would you schedule this as a daily report? _(Tests production mindset: incremental loads, idempotency, monitoring.)_
- How would you modify this query if a new column were added to the schema? _(Tests adaptability: whether the candidate can extend the query without rewriting it.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/region_with_best_uptime)
- [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.