Flag API Customers Whose Latency Breached Their SLA Last Week
Last updated: November 29, 2026
Quick Overview
Given a request log table with tenant, model, timestamps, status and token counts, write SQL that reports each tenant's daily request count, p50 and p95 latency, and output tokens per second, and flags tenant-days where p95 latency exceeded that tenant's contracted SLA.
Inception
November 29, 20260
0
0 solved
Given a request log table with tenant, model, timestamps, status and token counts, write SQL that reports each tenant's daily request count, p50 and p95 latency, and output tokens per second, and flags tenant-days where p95 latency exceeded that tenant's contracted SLA.
Inception offers custom SLAs to enterprise customers and sells on speed, so reliability and account teams need daily SLA reports from API logs. Data engineers build these pipelines. The interviewer checks percentile aggregation, careful filtering of failed or streaming requests, and a correct join to contract data.
What the Interviewer Expects
- Clarify which latency is measured (end-to-end or time to first token)
- Exclude or separately count errored requests
- Use percentile aggregate functions grouped by tenant and day
- Join to SLA thresholds with a left join so tenants without SLAs still appear
- Guard against divide-by-zero in tokens-per-second
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute this incrementally in a nightly job?
- Should a breach be judged on p95 per day or per hour?
- How would you attribute a breach to our infrastructure versus very long prompts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
api_requests(request_id, tenant_id, model, started_at, finished_at, status, input_tokens, output_tokens) and tenant_sla(tenant_id, p95_latency_ms). Latency is end-to-end, `finished_at - started_at...
Approach
Filter to last week, compute per-request latency in ms, aggregate by tenant and day with percentile_cont, compute throughput as total output tokens over total generation seconds, then left join SLA ...