Compute Hourly p50 and p99 Latency per API From Request Logs
Last updated: November 29, 2026
Quick Overview
Given request logs (api_name, request_ts, latency_ms, status_code), use pandas to compute for each API and UTC hour the request count, median latency, 99th percentile latency and 5xx error rate, suppressing percentiles for hours with too few requests to be meaningful.
Amazon
November 29, 20260
0
0 solved
Given request logs (api_name, request_ts, latency_ms, status_code), use pandas to compute for each API and UTC hour the request count, median latency, 99th percentile latency and 5xx error rate, suppressing percentiles for hours with too few requests to be meaningful.
AWS service teams set and review latency SLOs on tail percentiles like p99, not averages, and engineers are expected to slice logs themselves during operational reviews. This screen checks groupby with quantiles, time bucketing, and the judgment that p99 over a handful of requests is noise.
What the Interviewer Expects
- Bucket timestamps with dt.floor to the hour after parsing as UTC
- Compute quantiles per group and reshape them into columns
- Explain why p99 should not be averaged across hours or hosts
- Guard against tiny samples with a minimum request count
- Compute error rate as a mean of a boolean flag
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 a daily p99 from hourly data, and why can't you average hourly p99s?
- How would you do this on billions of log lines (t-digest, HDR histograms)?
- Should failed requests be included in the latency distribution?
- How would you alert when p99 exceeds the SLO for three consecutive hours?
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
logs(api_name, request_ts, latency_ms, status_code), one row per request, timestamps in UTC.- Output grain: API and hour. Errors are 5xx only; 4xx are client errors and do not count against the s...
Approach
- Parse to UTC and
floor("h")for the bucket. - One
groupbyfor count and error rate (mean of a boolean). quantile([0.5, 0.99])per group returns a long Series indexed by the quantile; `uns...