Memory-Heavy Pods
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
- ESPN
Problem
The SRE team is profiling mid-range memory consumers across the Kubernetes cluster. Pull all unique pod names where memory usage falls between 100 and 500.
Memory-hungry workloads.
Tables
k8s_pods
Columns: pod_id INTEGER, pod_name TEXT, nspace TEXT, status TEXT, restarts INTEGER, cpu_used REAL, mem_used REAL
| pod_id | pod_name | nspace | status | restarts | cpu_used | mem_used |
|---|---|---|---|---|---|---|
| 2043 | payment-003ef | production | Pending | 0 | 0.011 | 37 |
| 2086 | search-003f6 | staging | CrashLoopBackOff | 0 | 0.022 | 74 |
| 2129 | gateway-003fd | monitoring | Completed | 0 | 0.033 | 111 |
| 2172 | worker-00404 | kube-system | Error | 0 | 0.044 | 148 |
| 2215 | cron-0040b | default | Terminating | 0 | 0.055 | 185 |
| 2258 | ml-serve-00412 | production | Running | 0 | NULL | NULL |
| 2301 | cache-00419 | staging | Pending | 0 | 0.077 | 259 |
| 2344 | auth-00420 | monitoring | CrashLoopBackOff | 0 | 0.088 | 296 |
| 2387 | payment-00427 | kube-system | Completed | 0 | 0.099 | 333 |
| 2430 | search-0042e | default | Error | 0 | 0.11 | 370 |
Expected output
| pod_name |
|---|
| gateway-003fd |
| worker-00404 |
| cron-0040b |
| cache-00419 |
| auth-00420 |
Worked solution and explanation
Why this problem exists in real interviews
The interviewer wants to see you apply query construction to k8s_pods.pod_name while accounting for the distribution of nspace. This surfaces as a fundamentals check because small logic errors produce results that look correct at a glance.
Break down the requirements
Step 1: Read from k8s_pods
The query targets k8s_pods with 7 columns. Identify which columns are needed for the output.
Step 2: Filter to the target rows
Use BETWEEN in the WHERE clause to select the target range. This is both readable and optimizable by the query planner.
Step 3: Return the result set
Select the required columns with any necessary aliasing or formatting.
The solution
SELECT DISTINCT pod_name
FROM k8s_pods
WHERE mem_used BETWEEN 100 AND 500Common follow-up questions
- What happens to your result if `k8s_pods`.pod_name contains NULLs for some rows? (Tests whether the candidate accounts for NULL behavior in aggregates and comparisons on `pod_name`.)
- How would you verify that your aggregation on `k8s_pods`.pod_id is not double-counting due to duplicate rows? (Tests data quality awareness and deduplication strategies.)
- With millions of distinct values in `k8s_pods`.pod_id, what index strategy would you use to keep this query performant? (Tests indexing knowledge specific to high-cardinality columns like `pod_id`.)