Build a Per-Region Search Latency Percentile Table in Pandas
Last updated: November 29, 2026
Quick Overview
From raw request logs, build a table of daily p50, p95 and p99 latency per serving region with request counts, and a wide date by region matrix of p95 for a dashboard.
0
0
0 solved
From raw request logs, build a table of daily p50, p95 and p99 latency per serving region with request counts, and a wide date by region matrix of p95 for a dashboard.
Google cares about tail latency, and engineers are expected to look at percentiles, not averages. This pandas round question checks groupby with multiple quantiles, reshaping with unstack and pivot, and sensible treatment of errors and small samples.
What the Interviewer Expects
- Group by date and region and compute several quantiles at once
- Reshape quantile output into named columns
- Attach request counts and filter small groups
- Pivot to a wide matrix for display
- Explain why averages hide tail problems and why percentiles cannot be averaged across groups
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 global p99 from per-region p99s? Can you?
- With 10 billion requests a day, how would you compute these percentiles?
- How would you flag a region whose p99 regressed versus last week?
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(ts, region, endpoint, latency_ms, status), one row per request. I exclude 5xx responses from latency (they often fail fast or time out and should be tracked as error rate). Days are UTC. Groups...
Approach
groupby([...])['latency_ms'].quantile([0.5, 0.95, 0.99]) returns a Series with an extra index level for the quantile. unstack() moves that level into columns, which I rename to p50, p95, p99. `g.s...