Hourly p99 Ad Request Latency by Merging Per-Minute Histograms

Last updated: November 29, 2026

Quick Overview

Ad servers emit per-minute latency histograms with fixed bucket bounds instead of raw samples. Write Python that merges them into hourly histograms and estimates the p99 latency per hour from the merged buckets.

Meta
Data Manipulation (SQL/Python)
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


Ad servers emit per-minute latency histograms with fixed bucket bounds instead of raw samples. Write Python that merges them into hourly histograms and estimates the p99 latency per hour from the merged buckets.

A Python data round for Meta ads infrastructure engineers, testing whether you know that percentiles cannot be averaged but histograms can be summed. The interviewer checks bucket merging, the rank search, and an honest statement of the estimate's precision.

What the Interviewer Expects
  • Explain why averaging per-minute p99s is wrong
  • Sum bucket counts across minutes and servers
  • Find the bucket where the cumulative count reaches the target rank
  • Return the bucket upper bound and state the precision
  • Handle empty hours
Key Topics to Cover
histograms
percentiles
mergeable summaries
latency
Python
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you interpolate within the bucket for a better estimate?
  • What if servers use different bucket bounds?
  • How do t-digest or DDSketch compare with fixed buckets?
  • How would you compute a p99 over a day from these hourly merges?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Input: list of (hour, {upper_bound_ms: count}), one per server-minute. Each bucket counts requests with latency above the previous bound and at most its own. Bucket bounds are the same for all serve...

Approach

Percentiles do not compose: the p99 of an hour is not the mean or max of 60 minute-level p99s. Histograms do compose: sum counts per bucket across all minutes and servers. Then walk buckets in increas...


Submit Your Answer
Markdown supported